蓝桥-阶乘的约数

题目描述:

定义阶乘 n! = 1 × 2 × 3 × · · · × n。
请问 100! (100 的阶乘)有多少个约数。

代码:

import java.math.BigInteger;

public class 阶乘的约数 {
	public static void main(String[] args) {
		long[] nums = new long[102];		//素因数记录表
		//一个数可以分解为许多个质因数乘积的形式。 因为1不是质数,所以1没有质因数,所以素数表记录为0即可,阶乘从2分解开始。
		for(int i = 2; i <= 100; ++i) {
			//对每个数使用唯一分解定理。
			int n = i;
			for(int j = 2; j*j <= n; ++j) {
				if(n % j == 0) {
					while(n % j == 0) {
						n /= j;
						nums[j] ++;
					}
				}
			}
			//如果是质数上面的for循环不会执行的,因为上面的j不可能取到n
			if(n > 1) {
				nums[n] ++;
			}
		}
		long ans = 1;
		for(int i = 1; i < nums.length; ++i) {
			if(nums[i] > 0) {
				ans *= (nums[i] + 1);
			}
		}
		System.out.println(ans);
		
//		BigInteger sum = BigInteger.ONE;
//		for(int i = 1; i <= 100; ++i) {
//			sum = sum.multiply(BigInteger.valueOf(i));
//		}
		//算不出结果		
//		for(BigInteger i = BigInteger.ONE; i.compareTo(sum.sqrt().add(BigInteger.ONE)) < 0; i.add(BigInteger.ONE)) {
//			if(i == sum.sqrt() && sum.remainder(i) == BigInteger.ZERO) {
//				count.add(BigInteger.ONE);
//			}else if(sum.remainder(i) == BigInteger.ZERO) {
//				count.add(BigInteger.valueOf(2));
//			}
//		}
//		System.out.println(count);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值