POJ 1006
来源:互联网 发布:新开淘宝店没生意 编辑:程序博客网 时间:2024/06/05 16:25
中国剩余定理解题步骤
已知 n%3=2, n%5=3, n%7=2, 求n。
1.令x= n%3=2 , y= n%5=3 ,z= n%7=2
令5×7×a被3除余1,有35×2=70,即为70;
令3×7×b被5除余1,用21×1=21,即为21;
令3×5×c被7除余1,用15×1=15,即为15。
2.n =(70×x+21×y+15×z)%lcm(3,5,7) = 23 这是n的最小解
3.由n+i×lcm(3,5,7)可得到所有的数。
同样,这道题的解法就是:
已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i
使33×28×a被23除余1,用33×28×8=5544;
使23×33×b被28除余1,用23×33×19=14421;
使23×28×c被33除余1,用23×28×2=1288。
因此有(5544×p+14421×e+1288×i)% lcm(23,28,33) =n+d
又23、28、33互质,即lcm(23,28,33)= 21252;
所以有n=(5544×p+14421×e+1288×i-d)%21252
本题所求的是最小整数解,避免n为负,因此最后结果为n= [n+21252]% 21252
那么最终求解n的表达式就是:
n=(5544*p+14421*e+1288*i-d+21252)%21252;
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int p,e,i,d,n,index=1;
while(1)
{
cin>>p>>e>>i>>d;
if(p<0) break;
n=(5544*p+14421*e+1288*i-d+21252)%21252;
if(n==0) n=21252;
printf("Case %d: the next triple peak occurs in %d days.\n",index++,n);
}
}
- 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
- 使用jmeter的java执行oracle查询
- DEFINE_GUID
- Android webview上传文件失败,添加混淆解决办法
- 数据结构之栈(二)
- 虚拟机VMware无法识别USB设备(USB摄像头)问题及解决方法
- POJ 1006
- Android studio 各种快捷键,使用技巧
- 用JavaScript将数字转换为大写金额
- leetcode 58 求一个包含空格的字符串中最后一个字符串的长度
- eclipse调优
- hashmap,HashSet,ArrayList,ConcurrentMap 源码分析
- 博客说明
- Linux网络编程 -- socketpair的使用
- java读写properties配置文件