tag: Io AR for html sp amp on Ad c
# Include <cstdio> # include <cstring> # include <cstdlib> # include <algorithm> using namespace STD; typedef _ int64 ll; const int times = 20; ll factor [100], L; ll gcd (ll a, LL B) {return B? Gcd (B, A % B): A;} ll add_mod (ll a, LL B, ll N) {ll ans = 0; while (B) {If (B & 1) ans = (ANS + a) % N; B >>= 1; A = (a <1) % N;} return ans ;} ll pow_mod (ll a, ll M, ll N) {ll ans = 1; while (m) {If (M & 1) ans = add_mod (ANS, A, N ); m> = 1; A = add_mod (a, a, n);} return ans;} bool witness (ll a, ll N) {Int J = 0; ll M = n-1; while (! (M & 1) {J ++; m >>= 1 ;} ll x = pow_mod (a, m, n ); if (x = 1 | x = N-1) return true; while (j --) {x = add_mod (x, x, n); If (x = N-1) return true;} return false;} bool miller_rabin (ll n) {If (n <2) return false; If (n = 2) return true; If (! (N & 1) return false; For (INT I = 0; I <times; I ++) {ll A = rand () % (n-1) + 1; if (! Witness (A, n) return false;} return true;} ll pollard_rov (ll n, ll c) {ll I = 1, x = rand () % (n-1) + 1, y = x, K = 2, D; // srand (Time (null); While (true) {I ++; X = (add_mod (X, x, n) + C) % N; D = gcd (Y-X, n); If (D> 1 & D <n) return D; if (y = x) return N; if (I = k) {Y = x; k <= 1 ;}} void get_fact (LL N, ll K) {If (n = 1) return; If (miller_rabin (N) {factor [L ++] = N; return;} ll p = N; while (P> = N) {P = pollard_rov (P, K --);} get_fact (P, K); get_fact (N/P, K );}
Miller_rabin large prime number test and pollard_rov integer decomposition Template