poj1006生理周期

#include<vector>
#include<iostream>
using namespace std;
int arr[3]={23,28,33};
int gcd(int a,int b,int& x,int& y){
    if(b==0)
    {
        x=1;y=0;
        return a;
    }
    int q=gcd(b,a%b,x,y);
    int temp=x;
    x=y;
    y=-(y*a/b-temp);
    return q;
}
int main()
{
    int x,y,m=28*23*33;
    vector<int* > vrr;
    while(1)
    {
        int* v=new int[4];
        for (int i = 0; i < 4; ++i)
        {
            cin>>v[i];
        }
        int count=0;
        for (int i = 0; i < 4; ++i)
        {
            if(v[i]==-1)
                count++;
        }
        if(count==4)
            break;
        vrr.push_back(v);
    }
    for (int j = 0; j < vrr.size(); ++j)
    {
        int res=0;

        for (int i = 0; i < 3; ++i)
        {
            gcd(m/arr[i],arr[i],x,y);
            res+=m/arr[i]*x*vrr[j][i];
        }
        res=res%21252;
        while(res<=0)
            res+=21252;
        cout<<"Case "<<j+1<<": the next triple peak occurs in "<<res-vrr[j][3]<<" days."<<endl;
    }
    return 0;
}
/*
Sample Input

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
Sample Output

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.
*/
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值