题目链接:

  http://poj.org/problem?id=1006

  http://acm.hdu.edu.cn/showproblem.php?pid=1370

题目大意

  (X+d)%23=a1,(X+d)%28=a2,(X+d)%33=a3,给定a1,a2,a3,d,求最小的X。

题目思路:

  【中国剩余定理】

  23,28,33互素,可以套中国剩余定理。

  也可以直接手算逆元。

  33×28×a模23的逆元为8,则33×28×8=5544;

  23×33×b模28的逆元为19,则23×33×19=14421;

  23×28×c模33的逆元为2,  则23×28×2=1288。

  因此有(5544×p+14421×e+1288×i)%lcm(23,28,33)=n+d (lcm(23,28,33)= 21252)

  所以n=(5544×p+14421×e+1288×i-d)%21252

  本题所求的是最小整数解,避免n为负,因此最后结果 n=(n+21252)% 21252

  so n=(5544*p+14421*e+1288*i-d+21252)%21252;

  

 1 //
 2 //by coolxxx
 3 //
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<memory.h>
 9 #include<time.h>
10 #include<stdio.h>
11 #include<stdlib.h>
12 #include<string.h>
13 //#include<stdbool.h>
14 #include<math.h>
15 #define min(a,b) ((a)<(b)?(a):(b))
16 #define max(a,b) ((a)>(b)?(a):(b))
17 #define abs(a) ((a)>0?(a):(-(a)))
18 #define lowbit(a) (a&(-a))
19 #define sqr(a) ((a)*(a))
20 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
21 #define eps (1e-8)
22 #define J 10000000
23 #define MAX 0x7f7f7f7f
24 #define PI 3.1415926535897
25 #define N 4
26 using namespace std;
27 typedef long long LL;
28 int cas,cass;
29 int n,m,lll;
30 LL ans;
31 int p[N],a[N];
32 LL exgcd(LL a,LL b,LL &x,LL &y)
33 {
34     if(!b){x=1,y=0;return a;}
35     LL d=exgcd(b,a%b,y,x);
36     y-=a/b*x;
37     return d;
38 }
39 LL CRT(int nn)
40 {
41     LL sum=0,tot=1,tott,x,y;
42     int i;
43     for(i=1;i<=nn;i++)tot*=p[i];
44     for(i=1;i<=nn;i++)
45     {
46         tott=tot/p[i];
47         exgcd(tott,p[i],x,y);
48         x=(x%p[i]+p[i])%p[i];
49         sum=((sum+a[i]*tott%tot*x)%tot+tot)%tot;
50     }
51     return sum;
52 }
53 int main()
54 {
55     #ifndef ONLINE_JUDGE
56 //    freopen("1.txt","r",stdin);
57 //    freopen("2.txt","w",stdout);
58     #endif
59     int i,j,k,ii;
60 //    for(scanf("%d",&cas);cas;cas--)
61 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
62 //    while(~scanf("%s",s))
63     p[1]=23;p[2]=28;p[3]=33;
64     while(~scanf("%d",&n))
65     {
66         ans=0;
67         a[1]=n;
68         scanf("%d%d%d",&a[2],&a[3],&lll);
69         if(a[1]+a[2]+a[3]+lll==-4)break;
70         ans=CRT(3);
71         ans=(ans-lll+p[1]*p[2]*p[3]-1)%(p[1]*p[2]*p[3])+1;
72         printf("Case %d: the next triple peak occurs in %lld days.\n",++cass,ans);
73     }
74     return 0;
75 }
76 /*
77 //
78
79 //
80 */

千万不要点

转载于:https://www.cnblogs.com/Coolxxx/p/5767742.html

【中国剩余定理】POJ 1006 HDU 1370 Biorhythms相关推荐

  1. poj 1006(中国剩余定理)

    中国剩余定理: <孙子算经>中有"物不知数"问题:"今有物不知其数,三三数之余二 ,五五数之余三 ,七七数之余二,问物几何?"答为"23& ...

  2. NUC1100 Biorhythms【中国剩余定理】

    Biorhythms 时间限制: 1000ms 内存限制: 65536KB 问题描述 Some people believe that there are three cycles in a pers ...

  3. HDU1370 Biorhythms【中国剩余定理】

    问题链接:HDU1370 Biorhythms. 问题描述:参见上文. 问题分析:本题可以直接用中国剩余定理来解,同余方程如下: X≡p(mod 23) X≡e(mod 28) X≡i(mod 33) ...

  4. 【HDU】5238 Calculator 【中国剩余定理+线段树】

    传送门:[HDU]5238 Calculator 题目分析: 模数可以拆成四个小素数:7,13,17,19. 这样我们可以分别对这几个素数跑答案,最后中国剩余定理搞一下就好.中间我们用线段树,保存每个 ...

  5. HDU 5768 Lucky7 (中国剩余定理 + 容斥 + 快速乘法)

    Lucky7 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crow ...

  6. HDU 5768 Lucky7(2016 Multi-University Training Contest 4 -1005)——中国剩余定理 + 容斥原理

    [传送门](http://acm.hdu.edu.cn/showproblem.php?pid=5768) Lucky7 Time Limit: 2000/1000 MS (Java/Others)  ...

  7. POJ 1006 Biorhythms

    题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天每一个周期.中有一天是高峰.在高峰这天,人会在相应的方面表现出色.例如,智力周期的高峰,人会思维敏 ...

  8. hdu 3579(中国剩余定理非互质)

    解题思路:这道题目因为不一定是互质的,所以直接套用中国剩余定理肯定是错的,,这里采用的是非互质的方法...之前的博客上面有详细的证明过程和算法,这里就不罗嗦了..但是这道题目在输出的时候有特定的要求, ...

  9. hdu 1573(中国剩余定理非互质情况)

    解题思路:这道题目有可能a[i],两两不互质,所以直接用中国剩余定理肯定是不对的..这里考虑非互质的情况 问题描述:给出bi,ni的值,且n1, n2, n3,-, ni两两之间不一定互质,求Res的 ...

最新文章

  1. 清华北大“世界排名断崖式下跌”?
  2. PostCss 从0开始
  3. 我学员的一个问题及其我对之的解答,关于lr返回值问题
  4. 蓝桥杯JAVA省赛2013-----B------3(振兴中华)
  5. 区分大小屏幕_VESA持续推动DisplayHDR认证计划,你的屏幕属于何种等级吗?
  6. C++运算符重载函数作为类成员函数和友元函数
  7. Spring 容器简介
  8. jQuery-处理元素内容、表单元素
  9. [UE4]响应鼠标点击
  10. ubuntu创建用户的两种方式
  11. MYSQL问题解决方案:Access denied for user ‘root‘@‘localhost‘ (using password:YES)
  12. 【转】MongoDB学习笔记(查询)
  13. CSS3中(2D、3D、动画)重点整理
  14. 软考数据库系统工程师复习资料(完全版)
  15. 修改整个app的字体
  16. 更改win11鼠标指针样式
  17. 通过Homestead安装Laravel
  18. 数学建模:SPSS线性回归分析——逐步回归分析
  19. iPad pro能运行c语言吗,科技:与苹果iPad Pro的USB-C兼容或不兼容的配件你都知道吗?...
  20. excel poi 加背景图_java 在Excel中插入图片 POI实现

热门文章

  1. 一道面试题,想明白之后好像锤自己几下~~
  2. 图解MySQL数据库的安排和把持-1
  3. insertAdajcentHTML
  4. Java用数组的包文件_在Java中获取包内的类文件数组
  5. linux内核tor03,Linux内核x86架构引导协议4(翻译)
  6. C/C++中extern关键字
  7. login控件authenticate_Login.Authenticate 事件 (System.Web.UI.WebControls) | Microsoft Docs
  8. 简明 Python 编程规范
  9. 内存溢出分析之工具篇
  10. 1.1初识python