89 lines
1.4 KiB
C++
89 lines
1.4 KiB
C++
//TLE 30
|
|
|
|
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
#define int long long
|
|
|
|
const int MAX_N =5e6+5;
|
|
|
|
int binExp(int b,int e,int p){
|
|
int r=1;
|
|
while(e>0){
|
|
if(e%2==1)r=(r*b)%p;
|
|
b=(b*b)%p;
|
|
e=e>>1;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
int inverse(int b,int p){
|
|
return binExp(b, p-2,p);
|
|
}
|
|
|
|
#ifdef OITEST
|
|
#endif
|
|
#ifndef OITEST
|
|
#endif
|
|
|
|
#ifndef OITEST
|
|
int read(){
|
|
int x=0,w=1;
|
|
char ch=0;
|
|
while(!isdigit(ch)){
|
|
if(ch=='-')w=-1;
|
|
ch=getchar();
|
|
}
|
|
while(isdigit(ch)){
|
|
x=x*10+(ch-'0');
|
|
ch=getchar();
|
|
}
|
|
return x*w;
|
|
}
|
|
#endif
|
|
|
|
signed main(signed argc,char *argv[]){
|
|
ios::sync_with_stdio(false);
|
|
cin.tie(0);
|
|
#ifdef OITEST
|
|
assert(argc==3);
|
|
cout<<argv[1]<<endl<<argv[2]<<endl;
|
|
ifstream ifile(argv[1]);
|
|
ifstream afile(argv[2]);
|
|
assert(ifile.is_open()&&afile.is_open()==true);
|
|
stringstream ss;
|
|
#define cin ifile
|
|
#define cout ss
|
|
#endif
|
|
|
|
int n,p,k;
|
|
|
|
#ifdef OITEST
|
|
cin>>n>>p>>k;
|
|
#endif
|
|
|
|
#ifndef OITEST
|
|
n=read();
|
|
p=read();
|
|
k=read();
|
|
#endif
|
|
int ans=0;
|
|
int kp=k;
|
|
for(int i=1;i<=n;i++){
|
|
int a;
|
|
#ifdef OITEST
|
|
cin>>a;
|
|
#endif
|
|
#ifndef OITEST
|
|
a=read();
|
|
#endif
|
|
ans=((int)(kp*inverse(a, p))%p+ans)%p;
|
|
kp=(kp*k)%p;
|
|
}
|
|
cout<<ans<<endl;
|
|
#ifdef OITEST
|
|
int my,anser;
|
|
cout>>my;
|
|
afile>>anser;
|
|
assert(my==anser);
|
|
#endif
|
|
} |