#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define RDL(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} main(){ char rbuf[64]; read(0,rbuf,sizeof rbuf); char*rp=rbuf; RDL(a); RDL(b); RDL(c); { long p=c/(c&-c); long e=p; long i=3; while(e>1){ if(e%i==0){ p-=p/i; while(e%i==0){ e/=i; } } i+=2; if(i*i>e){ i=e; } } if(b>=p){ b=b%p+p; } } long z=0,y=0; long ac=a%c; for(long i=0;i>=1; e=e*e%c; } y+=x; if(++i==ac){ z=y; } } z+=a/c*y; z=z%c; { long n=0,d=0; while(++n,d=d<<8|0x30|z%10,z/=10); write(1,&d,n); } _exit(0); }