无脑套板子….
好像不需要理解什么意思的样子….
具体就是知道余数(除数积/当前)(除数积/当前 mod当前的逆元)求和….
就可以了…
板子有学长写好的…
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdio>
using namespace std;
long long a[3],m[3],n;
void ex_gcd(int a, int b, int &x, int &y) //板子
{
if (!b)
{
x = 1; y = 0;
return;
}
ex_gcd(b, a%b, y, x);
y -= (a / b) * x;
}
long long CRT()//板子
{
long long M = 1;
long long ans = 0;
for (int i = 0; i < n; i++)M *= m[i];
for (int i = 0; i < n; i++)
{
int x, y;
long long t = M / m[i];
ex_gcd(t, m[i], x, y);
ans += a[i] * t * x;
ans %= M;
}
ans = (ans + M) % M;
return ans;
}
int main()
{
int q,w,e,r;
n=3;
m[0]=23,m[1]=28,m[2]=33;
int u=0;
while(cin>>q>>w>>e>>r)
{
if(q==-1)break;
a[0]=q,a[1]=w,a[2]=e;
long long i=CRT()-r;
if(i<=0)i+=21252;
printf("Case %d: the next triple peak occurs in %lld days.\n",++u,i);
}
return 0;
}