数轮(3)中国剩余定理及求解模线性方程组

TQL移步大神讲解
POJ1006
AC:

#include <iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>

#define ll long long
#define INF 0x3f3f3f3f
#define EPS 1E-10

using namespace std;

void exgcd(int a,int b,int &g,int &x,int &y)
{
    if(!b)
    {
        g=b;    x=1;    y=0;
    }
    else
    {
        exgcd(b,a%b,g,y,x);     y-=x*(a/b);
    }
}
int main()
{
    const int M=23*28*33;
    /*
    int x,y,g;
    exgcd(M/23,23,g,x,y);
    cout<<(x%23+23)%23<<endl;

    exgcd(M/28,28,g,x,y);
    cout<<(x%28+28)%28<<endl;

    exgcd(M/33,33,g,x,y);
    cout<<(x%33+33)%33<<endl;
    */
    int p,e,i,d;
    int k=0;
    while(1)
    {
        scanf("%d%d%d%d",&p,&e,&i,&d);
        if(p==-1 && e==-1 && i==-1 &&d==-1)
            break;
        int s=(M/23*6*p+M/28*19*e+M/33*2*i-d+M)%M;
        if(!s)
            s=21252;
        printf("Case %d: the next triple peak occurs in %d days.\n",++k,s);

    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值