#include #include typedef long long int ll; int H,W,K; ll gcd(ll a, ll b) { int c; if (a < b) { c = a; a = b; b = c; } while (b != 0) { c = a%b; a = b; b = c; } return a; } ll lcm(ll a, ll b) { return a*b/gcd(a,b); } int M = 1000000007; // K^e (mod M)の計算 ll pow_mod_K(ll K, ll e) { if (K == 1) { return 1; } // K^(2^0), K^(2^1), ... , K^(2^n) static ll *KE = 0; int sz = 0; int i; if (KE == 0) { i = H; while (i != 0) { sz++; i>>=1; } sz++; i = W; while (i != 0) { sz++; i>>=1; } sz++; KE = (ll *)malloc(sizeof(ll)*sz); KE[0] = K%M; for (i=1; i>=1; } return K2; } // B^e (mod M)の計算 ll pow_mod(ll B, ll e) { if (B == 1) { return 1; } ll B2 = 1; B %= M; while (e != 0) { if (e&1) { B2 *= B; B2 %= M; } B = B*B; B %= M; e>>=1; } return B2; } // (2^3)^9 < 10^9 < (2^4)^9 ll P[4*9]; int E[4*9]; int Pend = 0; int factor(ll N) { ll p; int e; p=2; if (N%p == 0) { P[Pend] = p; e=1; for (N/=p; N%p==0; N/=p) e++; E[Pend] = e; Pend++; } for (p=3; p*p<=N; p+=2) { if (N%p == 0) { P[Pend] = p; e=1; for (N/=p; N%p==0; N/=p) e++; E[Pend] = e; Pend++; } } if (N != 1) { P[Pend] = N; E[Pend] = 1; Pend++; } return 0; } // e >= 0 // d^e ll pwr(ll d, int e) { if (d == 1) { return 1; } ll dd = 1; while (e != 0) { if (e&1) { dd *= d; } d = d*d; e>>=1; } return dd; } int cmpr(const void *a, const void *b) { if (*(ll *)a < *(ll *)b) { return -1; } else if (*(ll *)a > *(ll *)b) { return 1; } else { return 0; } } // Nの全約数生成 void initD(int N, ll **aD, int *aDsz) { Pend = 0; factor(N); int i; ll *D; int Dsz = 1; for (i=0; i