POJ 1006 Biorhythms 数论(孙子定理)

POJ 1006 Biorhythms 数论(孙子定理),第1张

题目地址: http://poj.org/problem?id=1006&lang=default&change=true

这是一道变形的孙子定理的题目,直接用公式。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

/*
freopen("input.txt",  "r", stdin);  //读数据
freopen("output.txt", "w", stdout); //注释掉此句则输出到控制台
*/


int main()
{
    int n,lcm,a,b,c,d,casei=0;
    int k1,k2,k3;
    while(cin>>a>>b>>c>>d&&(a+b+c+d)!=-4)
    {
        lcm=21252;//lcm(23,28,33);
        k1=5544;//k1%28=k1%33=0,k1%23=1;
        k2=14421;//k2%23=k2%33=0,k2%28=1;
        k3=1288;//k3%28=k3%23=0,k3%33=1;
        n=(k1*a+k2*b+k3*c-d+lcm)%lcm;
        if(n==0)
            n=lcm;
        printf("Case %d: the next triple peak occurs in %d days.\n",++casei,n);
    }
    return 0;
}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/2083995.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存