题目描述
给定 n 个数 Ai,问能满足 m! 为∑ni=1(Ai!) 的因数的最大的 m 是多少。其中 m! 表示 m 的阶乘,即 1 × 2 × 3 × · · · × m。
输入格式
输入的第一行包含一个整数 n 。
第二行包含 n 个整数,分别表示 Ai,相邻整数之间使用一个空格分隔。
输出格式
输出一行包含一个整数表示答案。
样例输入
3
2 2 2
样例输出
3
1 import java.util.Scanner; 2 // 1:无需package 3 // 2: 类名必须Main, 不可修改 4 5 public class Main { 6 public static void main(String[] args) { 7 Scanner scan = new Scanner(System.in); 8 int n = scan.nextInt(); 9 //记录最小值 10 int result = Integer.MAX_VALUE; 11 int[] nums = new int[n]; 12 //输入同时找出最小值 13 for (int i = 0; i < n; i++) { 14 nums[i] = scan.nextInt(); 15 if (nums[i] < result) { 16 result = nums[i]; 17 } 18 } 19 //记录有几个result! 20 int k = 0; 21 while(true) { 22 //每次统计result!的个数 23 for (int j = 0; j < n; j++) { 24 if (nums[j] == result) { 25 k++; 26 } 27 } 28 //如果有并且是result+1的倍数,说明还能表示成(result+1)! 29 if (k != 0 && k % (result + 1) == 0) { 30 k = k / (result + 1); 31 //重新记录有多少个(result+1)! 32 result++; 33 } else { 34 break; 35 } 36 } 37 System.out.print(result); 38 scan.close(); 39 } 40 41 }
标签:scan,int,nums,++,result,阶乘 From: https://www.cnblogs.com/saucerdish/p/18045329