55 lines
934 B
C++
55 lines
934 B
C++
|
#include<bits/stdc++.h>
|
||
|
using namespace std;
|
||
|
#define int long long
|
||
|
|
||
|
int binExp(int b,int e,int m){
|
||
|
int r=1;
|
||
|
while(e>0){
|
||
|
if(e%2==1){
|
||
|
r=(r*b)%m;
|
||
|
}
|
||
|
b=(b*b)%m;
|
||
|
e=e>>1;
|
||
|
}
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
|
||
|
int inverse(int a,int p){
|
||
|
return binExp(a, p-2, p);
|
||
|
}
|
||
|
|
||
|
#ifdef OITEST
|
||
|
#endif
|
||
|
#ifndef OITEST
|
||
|
#endif
|
||
|
|
||
|
signed main(signed argc ,char* argv[]){
|
||
|
cin.sync_with_stdio(false);
|
||
|
cin.tie(0);
|
||
|
|
||
|
int n,p;
|
||
|
#ifdef OITEST
|
||
|
assert(argc==2);
|
||
|
string snum(argv[1]);
|
||
|
string ifilen=snum+".in";
|
||
|
string ofilen=snum+".out";
|
||
|
cout<<ifilen<<endl;
|
||
|
ifstream ifile(ifilen.c_str());
|
||
|
ifstream ofile(ofilen.c_str());
|
||
|
stringstream ss;
|
||
|
#define cin ifile
|
||
|
#define cout ss
|
||
|
#endif
|
||
|
cin>>n>>p;
|
||
|
|
||
|
for(int i=1;i<=n;i++){
|
||
|
cout<<inverse(i,p)<<endl;
|
||
|
#ifdef OITEST
|
||
|
int o,a;
|
||
|
ss>>o;
|
||
|
ofile>>a;
|
||
|
assert(o==a);
|
||
|
#endif
|
||
|
}
|
||
|
}
|