转载请注明出处:優YoU http://user.qzone.qq.com/289065406/blog/1309411846
中国剩余定理
韩信点兵 3路躲2 5纵多3 7纵多2
射人数为n n%3=2; n%5=3; n%7=2;
中国剩余定理 5*7*x1%3=1; 3*7*x2%5=1; 3*5*x3%7=1;
x1=2 x2=1 x3=1
n=(70*2+21*3+15*7)%lcm(3,5,7) 因为3,5,7互质所以为105;
poj
(n+d)%23=p (n+d)%28=e (n+d)%33=i
28*33*x1%23=1 23*33*x2%28=1 23*28*x3%33=1
x1=8 x2=19 x3=2
n+d=(28*33*8+23*33*19+23*28*2)%lcm(23,28,33)
n=(28*33*8+23*33*19+23*28*2-d)%lcm(23,28,33)
#include <iostream>
using namespace std;
int main()
{
int p,e,i,d,Case=1;
while(cin>>p>>e>>i>>d)
{
if(p==-1 && e==-1 && i==-1 && d==-1)
break;
int ac = (5544*p+14421*e+1288*i-d+21252)%21252;
if(ac==0)
cout<<"Case "<<Case++<<": the next triple peak occurs in 21252 days."<<endl;
else
cout<<"Case "<<Case++<<": the next triple peak occurs in "
<<ac<<" days."<<endl;
}
return 0;
}