B - Biorhythms

https://vjudge.net/contest/278754#problem/B

#include<iostream>
#include<cstdio>
#include<cmath>
#define  ll long long
using namespace std;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if (b==0)
    {
        x=1;
        y=0;
        return a;
    }
    ll ans=exgcd(b,a%b,y,x);
    y=y-(a/b)*x;
    return ans;
}
ll r[10],d,i,j,t,k,l,g,x,y,ans;ll f[4]= {23,28,33},f1[4]= {924,759,644};
int main()
{
    scanf("%lld",&t);
    while (t--)
    {
        l=0;
        while (scanf("%lld%lld%lld%lld",&r[0],&r[1],&r[2],&d)){ ans=0;
            if (r[0]==-1&&r[1]==-1&&r[2]==-1) break;
            for (i=0; i<3; i++)
            {
                g=exgcd(f1[i],f[i],x,y);
                ans=(ans+x*r[i]*f1[i])%21252;
            }
            ans=(ans%21252+21252)%21252;
            while (ans<=d) ans+=21252;
            printf("Case %lld: the next triple peak occurs in %lld days.\n",++l,ans-d);
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值