描述 Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier.
0 0 0 0 0 0 0 100 5 20 34 325 4 5 6 7 283 102 23 320 203 301 203 40 -1 -1 -1 -1样例输出
Case 1: the next triple peak occurs in 21252 days. Case 2: the next triple peak occurs in 21152 days. Case 3: the next triple peak occurs in 19575 days. Case 4: the next triple peak occurs in 16994 days. Case 5: the next triple peak occurs in 8910 days. Case 6: the next triple peak occurs in 10789 days.这个题涉及数论中的剩余定理,先跳过去,过几天去图书馆找本数论看看。
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = 0;
while (sc.hasNext()) {
int p = sc.nextInt();
int e = sc.nextInt();
int i = sc.nextInt();
int d = sc.nextInt();
if (p == -1 && e == -1 && i == -1 && d == -1) {
break;
}
n++;
int days = (5544 * p + 14421 * e + 1288 * i - d) % (21252);
if (days <= 0) {
days = 23 * 28 * 33 + days;
}
System.out.println("Case " + n
+ ": the next triple peak occurs in " + days + " days.");
}
}
}