摘要:
1 //求解模方程 a^x = b(mod n) n为素数,无解返回-1 2 int log_mod(int a, int b, int n) { 3 int m, v, e = 1, i; 4 m = (int) sqrt(n+0.5); 5 v = inv(pow_mod(a, m, n), n); 6 map x; 7 x[1] = ... 阅读全文
摘要:
1 //n个方程,x=a[i](mod m[i]) 2 3 LL china(int n, int *a, int *m) { 4 LL M = 1, d, y, x = 0; 5 for(int i = 0; i < n; i++) M *= m[i]; 6 for(int i = 0; i < n' i++) { 7 LL w = ... 阅读全文
摘要:
//计算欧拉phi函数,phi(n)为不超过n且与n互素的整数个数 int euler_phi(int n) { int m = (int)sqrt(n+0.5); int ans = n; for(int i = 2; i 1) ans = ans / n * (n-1); return ans; } //用类似筛法计算phi_table int... 阅读全文
摘要:
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; } 阅读全文