来自澳大利亚的兵


私信TA

用户名:zhangjun678

访问量:2960

签 名:

等  级
排  名 244
经  验 5875
参赛次数 0
文章发表 28
年  龄 0
在职情况 学生
学  校 djtu
专  业 计算机科学与技术

  自我简介:

喜欢数学,编程小白

TA的其他文章

解题思路:

注意事项:

参考代码:


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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区