From test instructions, ANW = (b-1) *b^ (n-1)%c, emphasized, in order to b^ (n-1).
The weak slag can only push propaganda.
Phi (c) is less than C and the number of coprime with C.
When X >= Phi (c): A^x = A (X%phi (c) + phi (c)).
When X < Phi (c): Direct request is possible.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < cstdio> #include <queue> #include <cmath> #include <stack> #include <map> #include <ctime > #include <iomanip> #pragma comment (linker, "/stack:1024000000"); #define EPS (1e-6) #define _LL Long long# Define ULL unsigned long long#define LL __int64#define INF 0x3f3f3f3f#define Mod 1000000007/** I/O Accelerator Interface. . **/#define G (C=getchar ()) #define D isdigit (g) #define P x=x*10+c-' 0 ' #define N x=x*10+ ' 0 '-c#define pp l/=10,p#define nn l/= 10,ntemplate<class t> inline t& RD (T &x) {char C; while (!D); x=c-' 0 '; while (d) p; return x;} Template<class t> inline t& RDD (T &x) {char C; while (g,c!= '-' &&!isdigit (c)); if (c== '-') {x= ' 0 '-G; while (d) n; } else {x=c-' 0 '; while (d) p; } return x;} Inline double& RF (double &x)//scanf ("%lf", &x); { char c; while (g,c!= '-' &&c!= '. &&!isdigit (c)); if (c== '-') if (g== '. ') {x=0; Double l=1; while (d) nn; X*=l; } else {x= ' 0 '-C; while (d) n; if (c== '. ') {Double l=1; while (d) nn; X*=l; }} else if (c== '. ') {x=0; Double l=1; while (d) pp; X*=l; } else {x=c-' 0 '; while (d) p; if (c== '. ') {Double l=1; while (d) pp; X*=l; }} return x;} #undef nn#undef pp#undef n#undef p#undef d#undef gusing namespace Std;char s[1000010];int b[1000010],n[1000010]; LL C,b,n;bool vis[1000010]; LL Prime[1000010];int Top; ll Euler (ll N) {ll ret=1,i; for (i=2; i*i<=n; i++) {if (n%i==0) {n/=i,ret*=i-1; while (n%i==0) n/=i,ret*=i; }} if (N> 1) ret*=n-1; return ret;} ll Cal (int *n,ll c,bool &mark) {ll re = 0; for (int i = 0; N[i]! =-1; ++i) {re *= 10,re + = N[i]; if (re >= c) Mark = True,re%= C; } return re;} LL QM (ll a,ll b,ll N) {ll ret=1; LL Tmp=a; while (b) {if (b&1) ret=ret*tmp%n; tmp=tmp*tmp%n; b>>=1; } return ret;} int main () {int i,j; scanf ("%s", s); for (i = 0; s[i]! = ' + '; ++i) b[i] = s[i]-' 0 '; B[i] =-1; scanf ("%s", s); for (i = 0; s[i]! = ' + '; ++i) n[i] = s[i]-' 0 '; N[i] =-1; scanf ("%i64d", &c); LL MAXN = sqrt (c); memset (vis,false,sizeof (VIS)); Top = 0; for (i = 2; I <= MAXN, ++i) if (vis[i] = False) for (j = i+i,prime[top++] = i; j <= Maxn; j + = i) VIS[J] = true; LL phi = Euler (c), B1; BOOL Mark = false; b = Cal (B,c,mark); Mark = false; n = Cal (N,phi,mark); B1 = (b-1+c)%c; if (Mark = = True) n = (n-1+phi)%phi + phi; else n--; LL anw = B1*QM (b,n,c)%c; if (anw = = 0) Anw = c; printf ("%i64d\n", ANW); return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Codeforces 17D Notepad Simple number theory