相傳韓信才智過人,從不直接清點自己部下的人數,只要讓士兵先後以三人一排、五人一排、七人一排地變換隊形,而他每次只掠一眼隊伍的排尾就知道總人數了。輸入3個非負整數a,b,c ,表示每種隊形排尾的人數(a<3,b<5,c<7),輸出總人數的最小值(或報告無解)。已知總人數不小於10,不超過100 。
輸入
輸入3個非負整數a,b,c ,表示每種隊形排尾的人數(a<3,b<5,c<7)。
輸出
輸出總人數的最小值(或報告無解,即輸出No answer)。
樣例輸入:
2 1 6
樣例輸出:
41
樣例輸入:
2 1 3
樣例輸出:
No answer
import java.util.ArrayList;
import java.util.Scanner;
/*
* 韓信點兵
*/
public class Main {
static int count = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a, b, c;
while (scanner.hasNext()) {
a = scanner.nextInt();
b = scanner.nextInt();
c = scanner.nextInt();
count++;
answer(a, b, c);
}
}
public static void answer(int a, int b, int c) {
int i;
for (i = 10; i <= 100; i++) {
if (i % 3 == a && i % 5 == b && i % 7 == c) {
break;
}
}
count++;
if (i == 101) {
System.out.println("CASE " + count + ": " + "No answer");
} else {
System.out.println("CASE " + count + ": " + i);
}
}
}