国11阶乘约数-质因数分解
定义阶乘 n!=1×2×3×⋅⋅⋅×n。
请问 100!(100 的阶乘)有多少个正约数。
答案:39001250856960000
数学公式:
public class FactorialDivisors {public static void main(String[] args) {// 数组用于存储每个质数出现的次数int[] counts = new int[101];// 计算每个数的质因数分解,并记录每个质因数出现的次数for (int i = 2; i <= 100; i++) {int num = i;for (int j = 2; j <= Math.sqrt(num); j++) {while (num % j == 0) {counts[j]++;num /= j;}}if (num > 1) counts[num]++;}// 计算100!的正约数个数long result = 1;for (int i = 2; i <= 100; i++) {if (counts[i] > 0) result *= (counts[i] + 1);}// 输出结果System.out.println(result);}
}
既然理解不了那就背下来别折磨自己