解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class 包子凑数 {
static int dp[]=new int[100000];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int times = n;
int result = 0;
int temp = 0;
while (times > 0) {
int m = sc.nextInt();
if (times == n)
temp = m;
temp = gcd(temp, m);
for (int i = 1; i < dp.length; i++) {
if (i % m == 0)
dp[i] = 1;
if (i >= m && dp[i] == 0)
dp[i] = dp[i - m];
}
times--;
}
if (temp == 1) {
for (int i = 1; i < dp.length; i++) {
if (dp[i] == 0) {
result++;
}
}
System.out.println(result);
}
else {
System.out.println("INF");
}
}
public static int gcd(int a,int b){
return a%b==0?b:gcd(b,a%b);
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:578 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:563 |
WU-链表数据求和操作 (C++代码)浏览:1312 |
1908题解浏览:633 |
a+b浏览:432 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:561 |
1012题解浏览:861 |
关于float,double变量的几点说明浏览:1810 |
1051(奇了怪了)浏览:645 |