当前位置:网站首页>2022.6.30-----leetcode. one thousand one hundred and seventy-five
2022.6.30-----leetcode. one thousand one hundred and seventy-five
2022-07-01 05:36:00 【Lu 727】
// Statistical prime numbers , Count the permutations
int mod=(int)1e9+7;
public int numPrimeArrangements(int n) {
int cnt=0;
for(int i=2;i<=n;i++){
if(isPrime(i))
cnt++;
}
return (int)((factorial(cnt)%mod)*(factorial(n-cnt)%mod)%mod);
}
boolean isPrime(int num){
if (num == 0||num==1)
return false;
if (num == 2 || num == 3)
return true;
if (num % 6 != 1 && num % 6 != 5)
return false;
int end = (int) Math.pow(num,1.0/2);
for (int i = 5; i <= end; i += 6) {
if (num % i == 0 || num % (i + 2) == 0)
return false;
}
return true;
}
long factorial(int n){
if(n==0)
return 1;
return factorial(n-1)*n%mod;
}
边栏推荐
猜你喜欢

激活函数简述

云原生存储解决方案Rook-Ceph与Rainbond结合的实践

How to select conductive slip ring material

Mongodb學習篇:安裝後的入門第一課

0xc000007b the application cannot start the solution normally (the pro test is valid)

el-form表单新增表单项动态校验;el-form校验动态表单v-if不生效;

数字金额加逗号;js给数字加三位一逗号间隔的两种方法;js数据格式化

如何创建一个根据进度改变颜色的进度条

LRU cache for leveldb source code analysis

Practice of combining rook CEPH and rainbow, a cloud native storage solution
随机推荐
One click deployment of highly available emqx clusters in rainbow
Set set detailed explanation
Vérification simple de la lecture et de l'écriture de qdatastream
Is it safe for a novice to open a securities account?
Mathematical knowledge: finding the number of divisors
Txncoordsender of cockroachdb distributed transaction source code analysis
tese_Time_2h
Causes of short circuit of conductive slip ring and Countermeasures
HDU - 1024 Max Sum Plus Plus(DP)
LRU cache for leveldb source code analysis
Web Security (IX) what is JWT?
Variable binding and deconstruction for rudimentary rust
Data governance: data governance management (Part V)
Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
HDU - 1069 Monkey and Banana(DP+LIS)
在Rainbond中一键部署高可用 EMQX 集群
Usage and principle of synchronized
HDU - 1069 Monkey and Banana(DP+LIS)
Multi table operation - foreign key cascade operation
QT waiting box production