数论还是只会(ex)gcd系列
多了个 天朝剩余定理
利用天朝剩余定理的模拟过程
#include <cstdio>
int temp,P,E,I,D,x,y,ans,i,a,b;
void ex_gcd (int a,int b,int &x,int &y) {
if(b) {
ex_gcd(b,a%b,x,y);
temp = x;
x = y;
y = temp - a / b * y;
}
else x = 1,y = 0;
}
void solve (int A,int B) {
a = A * B;
if(a == 644)
b = 33;
else {
if(a == 759)
b = 28;
else b = 23;
}
ex_gcd(a,b,x,y);
if(x < 0) {
x += (x / -b) * b;
if(x < 0)
x += b;
}
if(b == 23)
ans += x * a * (P + 1);
else {
if(b == 28)
ans += x * a * (E + 1);
else ans += x * a * (I + 1);
}
}
int main () {
while(++i) {
scanf("%d%d%d%d",&P,&E,&I,&D);
if(P == -1)
break;
solve(23,33);
solve(23,28);
solve(28,33);
ans %= 21252;
ans -= D + 1;
if(ans <= 0)
ans += 21252;
printf("Case %d: the next triple peak occurs in %d days.\n",i,ans);
ans = 0;
}
}
结论是
#include<cstdio>
int p,e,i,d,n,I,G = 21252;
int main () {
while(++I) {
scanf("%d%d%d%d",&p,&e,&i,&d);
if(p == -1) break;
n =(p * 5544 + e * 14421 + i * 1288 - d + G) % G;
if(n == 0) n += G;
printf("Case %d: the next triple peak occurs in %d days.\n",I,n);
}
}

本文探讨了数论的基本概念,重点介绍了天朝剩余定理,并通过实例展示了如何利用该定理解决实际问题。
282

被折叠的 条评论
为什么被折叠?



