摘要:
LL pow_mod(LL a, LL p, LL m) { if(p == 0) return 1; LL ans = pow_mod(a, p/2, m); ans = ans * ans % m; if(p % 2) ans = ans * a % m; return ans; } 阅读全文
摘要:
//gcd LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a%b); } //exgcd void exgcd(LL a, LL b, LL &d, LL &x, LL &y) { if(!b) {d = a; x = 1; y = 0;} else {gcd(b, a%b, d, y, x); y -= x*(a... 阅读全文
摘要:
1 int vis[maxn]; 2 int prime[maxn]; 3 4 void sieve(int n) { 5 int m = sqrt(n + 0.5); 6 memset(m, 0, sizeof m); 7 for(int i = 2; i <= m; i++) if(!vis[i]) 8 for(int j = i*i... 阅读全文