poj 1006 Biorhythms

//POJ 1006 Biorhythms (中国剩余定理)
#include <cstdio>

int mo(int a,int b,int c)
{
 a*=b;
 int d=a;
 while (a%c!=1) a+=d;
 return a;
}

int main()
{
 int a,b,c;
 int d;
 int count=0;
 while (scanf("%d%d%d%d",&a,&b,&c,&d) )
 {
  if (a==-1 && b==-1 && c==-1 && d==-1)
   break;

  int ans=(mo(23,28,33)*c+mo(23,33,28)*b+mo(28,33,23)*a-d+21252) % 21252;
  if (!ans) ans=21252;
  printf("Case %d: the next triple peak occurs in %d days./n",++count,ans);
 }
 return 0;
}

你可能感兴趣的:(poj 1006 Biorhythms)