随笔分类 -  OI

欧里几德算法(辗转相除法)
摘要:/*求两个正整数 a 和 b 的 最大公约数 d则有 gcd(a,b) = gcd(b,a%b)证明: 设a%b = a - k*b 其中k = a/b(向下取整) 若d是(a,b)的公约数 则知 d|a 且 d|b 则易知 d|a-k*b 故d也是(b,a%b) 的公约数 若d是(b,a%b)的公 阅读全文

posted @ 2023-06-04 21:23 不是小朋友L 阅读(22) 评论(0) 推荐(0)

筛法--朴素筛法和埃式筛法和线性筛法
摘要:朴素筛法: #include <iostream> #include <algorithm> using namespace std; const int N=1000010; int primes[N],cnt; bool st[N]; void get_primes(int n){ for(in 阅读全文

posted @ 2023-05-31 22:20 不是小朋友L 阅读(121) 评论(0) 推荐(0)

分解质因数--试除法
摘要:#include <iostream>#include <cstring> #include <algorithm> using namespace std; void divide(int n){ for(int i=2;i<=n;i++) //这个地方是枚举到n { if(n%i==0) { i 阅读全文

posted @ 2023-05-28 14:36 不是小朋友L 阅读(80) 评论(0) 推荐(0)

质数的判定--试除法
摘要:#include <iostream> #include <cstring> #include <algorithm> bool is_prime(int n){ if(n<2)return false; for(int i=2;i<=n/i;i++) if(n%i==0)return false; 阅读全文

posted @ 2023-05-26 00:24 不是小朋友L 阅读(54) 评论(0) 推荐(0)

快速幂
摘要:第一次写的代码:#include <iostream> using namespace std; int main(){ int a,b,p; cin>>a>>b>>p; int res=1%p; while(b){ if(b&1) res=res*1ll*a%p; a=a*a*1ll%p; //这 阅读全文

posted @ 2023-05-06 00:06 不是小朋友L 阅读(34) 评论(0) 推荐(0)

导航