数学问题吧,有兴趣的可以研究一下“中国剩余定理”
// 1006.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> using namespace std; int main(int argc, char* argv[]) { int p=0,e=0,i=0,d=0; int a=23,b=28,c=33; int a1=0,b1=0,c1=0; for (int j=0;;j++) { if (a1!=0&&b1!=0&&c1!=0) { break; } if (a1==0) { if (j*28*33%23==1) { a1=j*28*33; } } if (b1==0) { if (j*23*33%28==1) { b1=j*23*33; } } if (c1==0) { if (j*23*28%33==1) { c1=j*23*28; } } } int res=0; int j=0; while(1) { cin>>p>>e>>i>>d; if (p==-1&&e==-1&&i==-1&&d==-1) { break; } res=(a1*p+b1*e+c1*i-d+a*b*c)%(a*b*c); j++; if(res==0) res=a*b*c; printf("Case %d: the next triple peak occurs in %d days. ",j,res); } return 0; }