–> 题目链接 <–

4148:生理周期

样例输入

0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1


样例输出

Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.


【代码】

#include<cstdio>
#include<cmath>
using namespace std;

#define LLint long long
void exgcd(LLint a, LLint b, LLint& x, LLint& y){
if(b == 0){
x = 1; y = 0;
}else{
LLint x0, y0;
exgcd(b, a%b, x0, y0);
x = y0;
y = x0 - a/b * y0;
}
}

LLint Inv(LLint a, LLint p){
LLint x, y;
exgcd(a, p, x, y);
return (x % p + p) % p;
}

int main(){
const int M = 23 * 28 * 33;
const int M1 = M/23, M2 = M/28, M3 = M/33;
int iM1 = Inv(M1, 23), iM2 = Inv(M2, 28), iM3 = Inv(M3, 33);
int K1 = iM1*M1, K2 = iM2*M2, K3 = iM3*M3;
int p, e, i, d, qcnt = 0;
while(scanf("%d%d%d%d", &p, &e, &i, &d) && (p != -1)){
p %= 23; e %= 28; i %= 33;
int x = (p*K1 + e*K2 + i*K3) % M;
int t = d/M;
int n = t*M + x; while(n <= d) n += M;
printf("Case %d: the next triple peak occurs in %d days.\n", ++qcnt, n-d);
}
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120