QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#407071 | #5099. 朝圣道 | Augenstern | Compile Error | / | / | C++14 | 2.6kb | 2024-05-07 22:01:07 | 2024-05-07 22:01:07 |
Judging History
answer
//#pragma GCC optimize(3)
#include<iostream>
#include<climits>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<vector>
//#include<random>
//#include<chrono>
#define int long long
//#define double long double
using namespace std;
const long long INF=INT_MAX/4ll;
//const long long mod=998244353;
//const long long mod=1000000007;
const double Pai=acos(-1);
namespace Exgcd {
int x,y;
int exgcd(int a,int b,int &x,int &y) {
if(!b) {x=1,y=0;return a;}
int d=exgcd(b,a%b,x,y);
int z=x;x=y;
y=z-(a/b)*y;
return d;
}
int calc(int a,int b,int p) {
if(a<0) a=-a,b=-b;
x=y=0;
int d=exgcd(a,p,x,y);
return (b/d*x%(p/d)+p/d)%(p/d);
}
}
using namespace Exgcd;
namespace Crt {
int cnt=0,s=1,sum,x,y;
int c[1000005],m1[1000005],m2[1000005];
struct o {
int x,y;
}e[1000005];
int CRT() {
s=1,sum=0;
for(int i=1;i<=cnt;i++) s*=e[i].x;
for(int i=1;i<=cnt;i++) m1[i]=s/e[i].x,m2[i]=calc(m1[i],1,e[i].x);
for(int i=1;i<=cnt;i++) c[i]=m1[i]*m2[i]*e[i].y,sum+=c[i],sum%=s;
return sum;
}
}
using namespace Crt;
namespace Exlucas {
int qp(int x,int y,int md) {
int res=1;x%=md;
while(y) {
if(y&1ll) y--,res*=x,res%=md;
y>>=1ll,x*=x,x%=md;
}
return res;
}
int Fastfac(int n,int p,int pk) {
if(!n) return 1;
int cyc=1,rem=1;
for(int i=1;i<=pk;i++) if(i%p) cyc*=i,cyc%=pk;
cyc=qp(cyc,n/pk,pk);
for(int i=0;i<=n%pk;i++) if(i%p) rem*=(i%pk),rem%=pk;
return Fastfac(n/p,p,pk)*cyc%pk*rem%pk;
}
int Sump(int n,int p) {
if(n<p) return 0;
return Sump(n/p,p)+(n/p);
}
int FastC(int n,int m,int p,int pk) {
int fz=Fastfac(n,p,pk),fm1=calc(Fastfac(m,p,pk),1,pk),fm2=calc(Fastfac(n-m,p,pk),1,pk);
int pkk=qp(p,Sump(n,p)-Sump(m,p)-Sump(n-m,p),pk);
return fz*fm1%pk*fm2%pk*pkk%pk;
}
void init() {
int pp=p;cnt=0;
for(int i=2;i*i<=p;i++) {
if(pp%i==0) {
int now=1;
while(pp%i==0) {
now*=i,pp/=i;
}
vt.push_back({i,now});
// e[++cnt]={now,FastC(n,m,i,now)};
}
}
if(pp!=1) vt.push_back({pp,pp});
for(auto i:vt) {
int x=i.first,y=i.second;
e[++cnt]={pp,FastC(n,m,pp,pp)};
}
}
int exLucas(int n,int m,int p) {
for(auto i:vt) {
int x=i.first,y=i.second;
e[++cnt]={y,FastC(n,m,x,y)};
}
return CRT();
}
}
using namespace Exlucas;
int n,m,p;
signed main() {
scanf("%lld%lld%lld",&n,&m,&p);
init();
printf("%lld",exLucas(n,m,p));
return 0;
}
Details
answer.code: In function ‘void Exlucas::init()’: answer.code:82:16: error: ‘p’ was not declared in this scope; did you mean ‘pp’? 82 | int pp=p;cnt=0; | ^ | pp answer.code:89:17: error: ‘vt’ was not declared in this scope 89 | vt.push_back({i,now}); | ^~ answer.code:93:19: error: ‘vt’ was not declared in this scope 93 | if(pp!=1) vt.push_back({pp,pp}); | ^~ answer.code:94:20: error: ‘vt’ was not declared in this scope 94 | for(auto i:vt) { | ^~ answer.code:96:32: error: ‘n’ was not declared in this scope 96 | e[++cnt]={pp,FastC(n,m,pp,pp)}; | ^ answer.code:96:34: error: ‘m’ was not declared in this scope 96 | e[++cnt]={pp,FastC(n,m,pp,pp)}; | ^ answer.code:96:42: error: no match for ‘operator=’ (operand types are ‘Crt::o’ and ‘<brace-enclosed initializer list>’) 96 | e[++cnt]={pp,FastC(n,m,pp,pp)}; | ^ answer.code:43:16: note: candidate: ‘constexpr Crt::o& Crt::o::operator=(const Crt::o&)’ 43 | struct o { | ^ answer.code:43:16: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const Crt::o&’ answer.code:43:16: note: candidate: ‘constexpr Crt::o& Crt::o::operator=(Crt::o&&)’ answer.code:43:16: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘Crt::o&&’ answer.code: In function ‘long long int Exlucas::exLucas(long long int, long long int, long long int)’: answer.code:100:20: error: ‘vt’ was not declared in this scope 100 | for(auto i:vt) { | ^~ answer.code:102:23: error: reference to ‘y’ is ambiguous 102 | e[++cnt]={y,FastC(n,m,x,y)}; | ^ answer.code:41:29: note: candidates are: ‘long long int Crt::y’ 41 | int cnt=0,s=1,sum,x,y; | ^ answer.code:24:15: note: ‘long long int Exgcd::y’ 24 | int x,y; | ^ answer.code:102:37: error: reference to ‘y’ is ambiguous 102 | e[++cnt]={y,FastC(n,m,x,y)}; | ^ answer.code:41:29: note: candidates are: ‘long long int Crt::y’ 41 | int cnt=0,s=1,sum,x,y; | ^ answer.code:24:15: note: ‘long long int Exgcd::y’ 24 | int x,y; | ^ answer.code:102:39: error: no match for ‘operator=’ (operand types are ‘Crt::o’ and ‘<brace-enclosed initializer list>’) 102 | e[++cnt]={y,FastC(n,m,x,y)}; | ^ answer.code:43:16: note: candidate: ‘constexpr Crt::o& Crt::o::operator=(const Crt::o&)’ 43 | struct o { | ^ answer.code:43:16: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const Crt::o&’ answer.code:43:16: note: candidate: ‘constexpr Crt::o& Crt::o::operator=(Crt::o&&)’ answer.code:43:16: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘Crt::o&&’ answer.code: In function ‘int main()’: answer.code:110:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 110 | scanf("%lld%lld%lld",&n,&m,&p); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~