POJ 1006
来源:互联网 发布:简单图片轮播js代码 编辑:程序博客网 时间:2024/05/01 13:33
刚开始以为是欧几里得扩展,是在想不出,就到网上搜了下,原来是所谓的中国剩余定理:
若某数x分别被d1、、…、dn除得的余数为r1、r2、…、rn,则可表示为下式:
x=R1r1+R2r2+…+Rnrn+RD
其中R1是d2、d3、…、dn的公倍数,而且被d1除,余数为1;
R1 、R2…、
Rn是d1、d2、…、dn-1的公倍数,而且被dn除,余数为1;
D是d1、d2、…、的最小公倍数;
R是任意整数,可根据实际需要决定;
且d1、、…、必须互质,以保证每个Ri(i=1,2,…,n)都能求得.
是这写了下面代码:
#include <stdio.h>
int r1,r2,r3;
int t1=23,t2=28,t3=33;
void getr(){
int tmp;
int lt;
tmp = t1*t2;
for(lt=1;;lt++){
if(tmp*lt%t3 ==1)
break;
}
r3=tmp*lt;
tmp=t2*t3;
for(lt=1;;lt++){
if(tmp*lt%t1==1)
break;
}
r1 = tmp*lt;
tmp=t1*t3;
for(lt=1;;lt++){
if(tmp*lt%t2==1)
break;
}
r2 = tmp*lt;
}
int main(){
int p,e,i,d;
int n;
int ca =1;
getr();
while(1){
scanf("%d %d %d %d",&p,&e,&i,&d);
if(p != -1){
n = (r1*p+r2*e+r3*i-d+21252)%21252;
if(n==0)
n=21252;
printf("Case %d: the next triple peak occurs in %d days.\n",ca++,n);
}
else
break;
}
}
- POJ[1006]
- POJ 1006
- poj 1006
- poj 1006
- poj 1006
- POJ 1006
- poj 1006
- poj 1006
- POJ-1006
- poj 1006
- POJ 1006
- poj 1006
- POJ 1006
- POJ-1006
- POJ 1006
- POJ 1006
- poj--1006
- POJ 1006
- 不用AuxDIBImageLoad()向opengl中载入bmp纹理
- 我看Chrome
- PHP设计模式之适配器模式,建造者模式,数据访问对象模式
- 多线程的那点事儿(之数据互斥)
- is not in the sudoers file的解决方法
- POJ 1006
- VirtualBox 共享配置(Linux)
- Job的提交—客户端
- 使用boot.ini启动YlmfOS,应该也能启动其他linux
- 【.Net基础】浅谈ADO.Net及其应用
- 这几天
- myeclipse连接数据库并且利用hibernate直接生成数据库表的java类
- 云计算 OpenStack架构预览
- JSplitPanel