标签:inf https .com art html ant pac thml margin
今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二。问物几何?
void exgcd(int a,int b,int &x,int &y) { if(b==0){ x=1; y=0; return;} exgcd(b,a%b,x,y); int tp=x; x=y; y=tp-a/b*y; } int china() { int ans=0,lcm=1,x,y; for(int i=1;i<=k;++i) lcm*=b[i]; for(int i=1;i<=k;++i) { int tp=lcm/b[i]; exgcd(tp,b[i],x,y); x=(x%b[i]+b[i])%b[i];//x要为最小非负整数解 ans=(ans+tp*x*a[i])%lcm; } return (ans+lcm)%lcm; }
标签:inf https .com art html ant pac thml margin
原文地址:https://www.cnblogs.com/donke/p/10306778.html