[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>题目描述
定义阶乘 n! = 1 × 2 × 3 × · · · × n。
请问 100! (100 的阶乘)有多少个约数。
* 数论的一个知识点:
思路:
举个例子
180=2 * 2 * 3 * 3 * 5=22*32 * 5
那么 2 的2 次方对应的约数有 1 2 4 (3个)
3的二次方约数有 1,3, 9 (3个)
5的约数有 1,5 (2个)
则180的约数个数有(1+2) * (1+2) * (1+1)=18个。直接模拟判断约数的个数即可
利用唯一分解定理,分解出质因数对应的的幂数
其中arr数组对应的是质因数的幂数,也就是 a1,a2,a3…
public class Main { public static void main(String[] args) { // 100 的阶乘有多少约数
int[] arr=new int[102]; //利用唯一分解定理分解100的阶乘 // 必须要从2开始 for (int i=2;i<=100;i++){
int n=i; for (int j=2;j*j<=n;j++ ){ while (n%j==0){// 当能够整除 的时候,对应余数的幂次加一 arr[j]
++; n/=j; } } //整除完了后如果剩下的n不为1,则当前的n为因子 if (n>1){ arr[n]++; } } long ans=1; for
(int i=2;i<=100;i++){ if (arr[i]>0){ ans*=(arr[i]+1); } } System.out.println(ans
); } }
其中我们判断在一定范围也可以通过下面 的isprime方法构造素数数组也可
public static boolean isprime(int x){ if (x==1) return false; for (int i=2;i<x;
i++){ if (x%i==0){ return false; } } return true; }