POJ 1006 Chinese Remainder Theory
来源:互联网 发布:非农数据从哪里看 编辑:程序博客网 时间:2024/06/06 09:08
https://www.youtube.com/watch?v=PM2D3xzqH_E
令 t mod 23 = a; t mod 28 = b; t mod 33 = c;
t= k * lcm(23, 28, 33) + x + y + z;
x= c1 * lcm (23, 28) 且 x mod 33 = c;
y= c2 * lcm (23, 33) 且 y mod 28 = b;
z= c3 * lcm (28, 33) 且 z mod 23 = a;
因为 lcm(23, 28, 33) mod 23=0 mod 28=0 mod 33=0
别人的,比我牛逼。。
令 t mod 23 = a; t mod 28 = b; t mod 33 = c;
t= k * lcm(23, 28, 33) + x + y + z;
x= c1 * lcm (23, 28) 且 x mod 33 = c;
y= c2 * lcm (23, 33) 且 y mod 28 = b;
z= c3 * lcm (28, 33) 且 z mod 23 = a;
因为 lcm(23, 28, 33) mod 23=0 mod 28=0 mod 33=0
所以,一步一步把mod加上去,具体见视频!
我的代码
#include<stdio.h>int x1,x2,x3,x4,a,b,c,d,e,f,g,x,y,z,nown,tot;int gcd(int a,int b){if (a%b==0)return b;int r=a % b;return gcd(b,r);}int lcm(int a, int b, int gcd){return gcd*a/gcd*b/gcd;}int main(){int a=23; int b=28; int c=33;int d=lcm(a,b,gcd(a,b)); int e=lcm(b,c,gcd(b,c));int f=lcm(a,c,gcd(a,c));int g=lcm(d, e, gcd(d,e));int casen=0;while (true){casen++;scanf("%d%d%d%d", &x1, &x2, &x3, &x4);if (x1==-1)break;int x= 1, y=1, z=1; //printf("d=%d e=%d f=%d\n", d,e,f);while (x*d%33!=x3%33)//有修改空间 //printf("x*d mod 33=%d\n",x*d%33);//getchar();//for(int i=0; i<=1e9; i++);x++;while (y*e%23!=x1%23)y++;while (z*f%28!=x2%28)z++;printf("x*d mod 33=%d x3 mod 33=%d\n", x*d % 33, x3 % 33);//printf("x=%d y=%d z=%d\n", x,y,z);tot=x*d+y*e+z*f;int nown=-tot/g; while (g*nown+tot<=x4 || g*nown+tot<x1 || g*nown+tot<x2 || g*nown+tot<x3)nown++;printf("Case %d: the next triple peak occurs in %d day", casen, g*nown+tot-x4);if (g*nown+tot-x4==1)printf(".\n");elseprintf("s.\n");}}
别人的,比我牛逼。。
/* 中国剩余定理:出自《孙子算经》 */#include<stdio.h>#define MAX 21252int main(){int p, e, i, d, n, count = 0;while( scanf("%d%d%d%d", &p, &e, &i, &d) != EOF ){ count++;if(p == -1 && e == -1 && i == -1 && d == -1){break; }n = ( 5544 * p + 14421 * e + 1288 * i - d ) % MAX;if( n <= 0 ) // 范围限制 {n += 21252; } printf("Case %d: the next triple peak occurs in %d days.\n", count, n );}return 0;}
阅读全文
0 0
- POJ 1006 Chinese Remainder Theory
- CRT(chinese remainder algorithm)
- Chinese Remainder Theorem
- HDU1788 Chinese remainder theorem again
- Chinese remainder theorem again + 数论
- hdu1788 Chinese remainder theorem again
- HDU1788-Chinese remainder theorem again
- hdu 1788 Chinese remainder theorem again
- Hdu 1788 Chinese remainder theorem again
- HDU 1788 Chinese remainder theorem again 数论
- hdu 1788 Chinese remainder theorem again
- HDU 1788 Chinese remainder theorem again
- hdu 1788 Chinese remainder theorem again(最小公倍数)
- 【数论】 HDOJ 1788 Chinese remainder theorem again
- Chinese remainder theorem again(HDU 1788)
- hdu 1788 Chinese remainder theorem again 最小公倍数
- HDU1788 Chinese remainder theorem again 最小公倍数
- HDOJ-1788 Chinese remainder theorem again(数论)
- 论文记录-Pruning Filters For Efficient ConvNets
- linux RTC 驱动模型分析
- Kotlin 第十一章:扩展
- Linux(Centos)之安装Nginx及注意事项 阅读目录 1.Nginx的简单说明 2.准备工作 3.安装SSL功能需要openssl库以及gzip模块需要的zlib库 4.安装 rewri
- Mysql中剔除重复字段并按主键降序排序后找出主键值最大的数据
- POJ 1006 Chinese Remainder Theory
- Qt如何执行bash命令,并获取返回结果
- 第七章 线程
- ViewTreeObserver
- libcurl学习笔记
- Android Studio中两个Activity之间的转换及数据的传递
- nginx学习随笔--sendfile
- 生成指定大小文件供测试
- Leetcode c语言-Longest Common Prefix