China Remainder Theorem
X = AI (mod mi) AI and MI are a group of numbers, and MI are mutually dependent, X
Make MI = m1 * m2 *~ MK, where Mi is not included.
Because Mi is mutually qualitative, there are X and Y,
St mi * Xi + Mi * Yi = 1
For Ei = mi * XI, the following conditions are available:
Then e0a0 + e1a1 + e2a2 + ~ + En-1 * an-1 is a solution of the equation.
Because n % 3 = 2, N % 5 = 3, N % 7 = 2 and 3, 5, 7
So that 5 × 7 is divided by 3 and 1, with 35 × 2 = 70;
So that 3 × 7 is divided by 5 to 1, and 21 × 1 = 21;
So that 3 × 5 is divided by 7 and 1, with 15 × 1 = 15.
(70 × 2 + 21 × 3 + 15 × 2) % (3 × 5 × 7) = 23
Similarly, this question should also be:
Divide 33 × 28 by 23 and divide 1 by 33 × 28 × 8 = 5544;
Divide 23 × 33 by 28 and divide 1 by 23 × 33 × 19 = 14421;
So that 23 × 28 is divided by 33 and 1, with 23 × 28 × 2 = 1288.
(5544 × P + 14421 × E + 1288 × I) % (23 × 28 × 33) = N + d
N = (5544 × P + 14421 × E + 1288 × I-d) % (23 × 28 × 33)
#include<stdio.h>#define P 5544#define E 14421#define I 1288#define ans 21252int main(void){ int p,e,i,d; int n,num=0; while(scanf("%d%d%d%d",&p,&e,&i,&d)) { if(p==-1) return 0; n=(P*p+E*e+I*i-d+ans)%ans; if(n==0) n=ans; printf("Case %d: the next triple peak occurs in %d days.\n",++num,n); } return 0;}