首页 > 代码库 > POJ 1006 Biorhythms

POJ 1006 Biorhythms

思路:伟大的中国同余定理。公式推导见这里:http://blog.csdn.net/shanshanpt/article/details/8724769

 

代码:

  

/*  中国剩余定理:出自《孙子算经》  */#include<stdio.h>#define MAX 21252int main(){    int p, e, i, d, n, count = 0;        while( scanf("%d%d%d%d", &p, &e, &i, &d) != EOF )    {                count++;        if(p == -1 && e == -1 && i == -1 && d == -1)        {            break;                }        n = ( 5544 * p + 14421 * e + 1288 * i - d ) % MAX;                if( n <= 0 )   // 范围限制         {            n += 21252;                }                printf("Case %d: the next triple peak occurs in %d days.\n", count, n );    }    return 0;}

 

POJ 1006 Biorhythms