您的位置:首页 > 其它

poj1006--中国剩余定理

2012-09-27 00:30 316 查看
    原题地址poj1006

    这里用到的是中国剩余定理

    源代码:

#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
int res;
int n=0;
while(cin>>a>>b>>c>>d&&(a!=-1||b!=-1||c!=-1||d!=-1))
{
n++;
a=a%23;
b=b%28;
c=c%33;
res=5544*a+14421*b+1288*c;
res%=21252;
if(res<=d)
{
res=21252-(d-res);
}
else
{
res=res-d;
}
cout<<"Case "<<n<<": the next triple peak occurs in "<<res<<" days."<<endl;
}
return 0;
}


    这里的5544,14421和1288都是特殊数,5544%28==0&&5544%33==0&&5544%23=1,所以(5544*a)%23==a,其它两个数同理。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c