解题思路:
注意事项:
参考代码:
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语言代码)浏览:495 |
ASCII帮了大忙浏览:749 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1311 |
1024题解浏览:809 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:489 |
模拟计算器 (C++代码)浏览:806 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:514 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:491 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:459 |
C语言训练-列出最简真分数序列* (C语言代码)浏览:609 |