Enter a B to calculate the number of p pairs. Q makes p * q = A & P <Q & P> = B
Directly big integer decomposition and DFS searches for all possible solutions
# Include <cstdio> # include <cstring> # include <cstdlib> # include <algorithm> # include <cmath> using namespace STD; typedef long ll; const int times = 25; ll factor [100], F [100]; int l, ll, ANS, num [100]; ll a, B; 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);} void DFS (ll x, int P, ll m) {If (x> m) return; if (P = ll) {If (x> = B & A/x> X) ans ++; // printf ("% LLD \ n", X ); return;} ll y = 1; for (INT I = 0; I <= num [p]; I ++) {DFS (x * y, p + 1, m); y * = f [p] ;}} int main () {int CAS = 1; int t; scanf ("% d", & T ); while (t --) {scanf ("% LLD", & A, & B); ll M = SQRT (a + 0.5); ans = 0; L = 0; get_fact (A, 120); sort (factor, factor + l); F [0] = factor [0]; num [0] = 1; LL = 1; for (INT I = 1; I <L; I ++) {If (factor [I]! = Factor [I-1]) {ll ++; F [ll-1] = factor [I]; num [ll-1] = 0;} num [ll-1] ++ ;} // For (INT I = 0; I <ll; I ++) // printf ("% LLD % d \ n", F [I], num [I]); DFS (1, 0, m); printf ("case % d: % d \ n", CAS ++, ANS);} return 0 ;}
Light OJ 1341 Aladdin and the flying carpet pollard_rov integer decomposition + DFS