poj1006

转载请注明出处:優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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值