第一种方法:可以利用剩余定理的公式解决day = (5544*p+14421*e+1288*i-d+21252)%21252。
第二种方法:先根据所给p e i求出第一次高峰出现时的p1 e1 i1。由于p1+23*k1=e1+28*k2=i1+33*k3=d+n,所以从1到21251遍历,若(d+n)%23==p1 && (d+n)%28==e1 && (d+n)%33==i1 ,则停止循环,按格式输出。
import java.lang.*;
import java.util.*;
public class Main{
public static void main(String args[]){
int count = 0;
Scanner in = new Scanner(System.in);
while(in.hasNext()){
count++;
int p = in.nextInt();
int e = in.nextInt();
int i = in.nextInt();
int d = in.nextInt();
if(p==-1 && e==-1 && i==-1 && d==-1){
break;
}
int day = (5544*p+14421*e+1288*i-d+21252)%21252;
if(day == 0) day = 21252;
System.out.println("Case " + count + ": the next triple peak occurs in " + day + " days.");
}
}
}