1292: 韩信点兵
程序员文章站
2024-03-16 15:57:10
...
题目
Description
相传韩信才智过人,从不直接清点自己的军队的个数,只要让士兵先后以三人一排,五人一排,七人一排,变换队形,而他每次只掠一眼队伍的排尾人数就知道总人数了,输入三个非负整数,a,b,c表示每种队形排尾的人数,(a < 3, b < 5,c < 7)输出总人数的最小值(或报告无解),已知总人数不超过100,不少于10人
Input
,输入三个非负整数,a,b,c表示每种队形排尾的人数,(a < 3, b < 5,c < 7)
Output
输出总人数的最小值(或报告无解)
Sample Input
2 1 6
2 1 3
Sample Output
41
No answer
代码块
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cn = new Scanner(System.in);
while(cn.hasNext()){
int a = cn.nextInt();
int b = cn.nextInt();
int c = cn.nextInt();
int i = 10;
for(;i<=100;i++){
if(i%3 ==a&&i%5==b&&i%7==c)
break;
}
if(i<=100)
System.out.println(i);
else System.out.println("No answer");
}
}
}
推荐阅读
-
1292: 韩信点兵
-
【LeetCode 1292】 Maximum Side Length of a Square with Sum Less than or Equal to Threshold
-
1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold
-
LeetCode-1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold
-
[leetcode] 1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold
-
[CF1292C] Xenon's Attack on the Gangs
-
数据库迁移1292错误
-
韩信点兵歇后语及故事由来
-
韩信点兵歇后语及故事由来
-
【一级讲解】韩信点兵——中国剩余定理