当前位置:网站首页>2022.6.30-----leetcode.1175
2022.6.30-----leetcode.1175
2022-07-01 05:25:00 【路Lu727】
//统计质数,计算排列数
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;
}
边栏推荐
- Set集合詳細講解
- Detailed explanation of set
- Like cloud functions
- C# wpf 使用DockPanel实现截屏框
- Global and Chinese market of digital badge 2022-2028: Research Report on technology, participants, trends, market size and share
- Cockroachdb: the resistant geo distributed SQL database paper reading notes
- How to traverse massive data in redis
- Global and Chinese markets of gps/gnss receiver modules 2022-2028: Research Report on technology, participants, trends, market size and share
- Web Security (x) what is OAuth 2.0?
- Programmers dig "holes" to get rich: if they find a loophole, they will be rewarded 12.72 million yuan
猜你喜欢

CockroachDB 分布式事务源码分析之 TxnCoordSender

Detailed explanation of set

Explanation of characteristics of hydraulic slip ring

Ebpf cilium practice (2) - underlying network observability

Typeorm framework

Practice of combining rook CEPH and rainbow, a cloud native storage solution

Thread process foundation of JUC

How to traverse massive data in redis

Rainbow combines neuvector to practice container safety management

Using nocalhost to develop microservice application on rainbow
随机推荐
More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv. so‘.
Rainbow combines neuvector to practice container safety management
Causes of short circuit of conductive slip ring and Countermeasures
El cascade echo failed; El cascader does not echo
了解 JVM 中几个相关问题 — JVM 内存布局、类加载机制、垃圾回收
HDU - 1024 Max Sum Plus Plus(DP)
Global and Chinese market of protection circuit modules 2022-2028: Research Report on technology, participants, trends, market size and share
实战:redux的基本使用
Vmware workstation network card settings and three common network modes
What things you didn't understand when you were a child and didn't understand until you grew up?
Receiving package install and uninstall events
导电滑环短路的原因以及应对措施
複制寶貝提示材質不能為空,如何解决?
Practice of combining rook CEPH and rainbow, a cloud native storage solution
如何创建一个根据进度改变颜色的进度条
Printk debugging summary
Rust hello-word
Use and principle of Park unpark
Global and Chinese market of digital badge 2022-2028: Research Report on technology, participants, trends, market size and share
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级