POJ 1006 Biorhythms 数论-(孙子定理)

题目地址: 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;

}


 

 

你可能感兴趣的:(poj)