+lucas theorem of the remainder theorem in China
The problem is asking G∑I|NCINMODP g^{\sum_{i|n}c_n^i} \mod P
Then Fermat theorem, becomes the exponent modp−1 \mod p-1
Modulus is composite, open to each small factorization do again, the last CRT merged can.
Note Fermat theorem ap−1≡1 (MODP) a^{p-1} \equiv 1 \pmod p is established, when and only if P p is a prime number, and A,p a,p coprime, but G g= modulus although does not satisfy the theorem, but the fast power can automatically die, and generally do not have problems, but the author of the forced construction of the index is also 0 Then hang up ...
#include <cstdio> #include <cmath> #define MOD 999911658 #define N 35618 using namespace std;
Namespace runzhe2000 {typedef long long ll;
int n, G, m[4] = {2,3,4679,35617}, a[4], fac[4][n], inv[4][n];
int C (int a, int b, int i) {if (a < b) return 0;
else if (a < M[i]) return (LL) fac[i][a] * inv[i][b] * Inv[i][a-b]% m[i];
else return (LL) c (A/m[i], b/m[i], i) * C (A%m[i], b%m[i], i)% m[i]; } int Fpow (int a, int b, int mod) {if (!) (
a%= (mod+1))) return 0;
int r = 1;
for (; b; b>>=1) {if (b&1) r= (LL) R*a%mod;
A= (ll) A*a%mod;
} return R;
} int CRT () {int r = 0;
for (int i = 0; i < 4; i++) {int Mi = mod/m[i];
int tmp = (LL) a[i] * Mi% mod * FPOW (MI, m[i]-2, m[i])% MoD;
(R + = tmp)%= MOD;
} return R; } void Main () {scanf ("%d%d", &n,&Amp
G);
for (int j = 0; J < 4; J + +) {int *f = Fac[j], *v = inv[j], mod = m[j]; F[0] = 1;
for (int i = 1; i < mod; i++) f[i] = (LL) f[i-1] * I% mod; V[1] = 1;
for (int i = 2; i < mod; i++) v[i] = (ll) (mod-mod/i) *v[mod%i]% MoD; V[0] = 1;
for (int i = 1; i < mod; i++) v[i] = (LL) v[i] * v[i-1]% mod; } for (int j = 1, JJ = sqrt (double) n), J <= JJ; j + +) if (n% j = = 0) {f
or (int i = 0; i < 4; i++) {(A[i] + = C (n, J, i))%= m[i];
if (n/j! = j) (A[i] + = C (n, n/j, i))%= m[i];
}} int a = CRT ();
printf ("%d\n", Fpow (G, A, mod+1)); }} int main () {Runzhe2000::main ();}