> 分析
>> 三个周期是三个互质数, 可以很简单的使用中国剩余定理
> 附代码
1 /* ------------------------- 2 * 中国剩余定理 3 * -------------------------*/ 4 #include "stdio.h" 5 6 int main(void) 7 { 8 int p = 0, e = 0, i = 0, d = 0 ; 9 int days = 0 ; 10 int count = 0 ; 11 12 while(1) 13 { 14 scanf("%d %d %d %d", &p, &e, &i, &d) ; 15 if(-1 == d) 16 break ; 17 18 /* 5544 为28和33的公倍数, 且5544 % 23 = 1 */ 19 /* 14421 为23和33的公倍数,且14421 % 28 = 1 */ 20 /* 1288 为23和28的公倍数,且1288 % 33 = 1 */ 21 /* 21252 = 23 * 28 * 33 */ 22 days = (5544 * p + 14421 * e + 1288 * i) % 21252 ; 23 if(days <= d) 24 days += 21252 ; 25 26 printf("Case %d: the next triple peak occurs in %d days.\r\n", 27 ++count, days - d) ; 28 } 29 30 return 0 ; 31 }
时间: 2024-11-05 22:56:51