当前位置:网站首页>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;
}
边栏推荐
- Global and Chinese market of broadband amplifiers 2022-2028: Research Report on technology, participants, trends, market size and share
- Lock free concurrency of JUC (leguan lock)
- Daily question -leetcode1175- permutation of prime numbers - Mathematics
- Variable binding and deconstruction for rudimentary rust
- Ebpf cilium practice (2) - underlying network observability
- SSGSSRCSR区别
- Some common commands of podman
- 了解 JVM 中几个相关问题 — JVM 内存布局、类加载机制、垃圾回收
- eBPF Cilium实战(2) - 底层网络可观测性
- How to create a progress bar that changes color according to progress
猜你喜欢

Application of industrial conductive slip ring

Tar command

Actual combat: gateway api-2022.2.13

Daily code 300 lines learning notes day 11

Unity drags and modifies scene camera parameters under the editor

Leetcode316- remove duplicate letters - stack - greedy - string

JDBC common interview questions

Daily question -leetcode1175- permutation of prime numbers - Mathematics

2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)

Unity项目心得总结
随机推荐
JDBC common interview questions
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
What things you didn't understand when you were a child and didn't understand until you grew up?
Usage and principle of synchronized
Explanation of characteristics of hydraulic slip ring
Mongodb learning chapter: introduction after installation lesson 1
Like cloud functions
Worried about infringement? Must share copyrightless materials on the website. Don't worry about the lack of materials for video clips
JDBC常见面试题
Introduction of 3D Modeling and Processing Software Liu Ligang, Chinese University of Science and Technology
Global and Chinese markets of InGaAs APD arrays 2022-2028: Research Report on technology, participants, trends, market size and share
0xc000007b the application cannot start the solution normally (the pro test is valid)
Unity project experience summary
Ebpf cilium practice (2) - underlying network observability
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
[Yugong series] February 2022 Net architecture class 005 ABP vNext Net core web application getting started configuration
QDataStream的簡單讀寫驗證
移动端常用解决方案
基于TI DRV8424驱动步进电机实现调速和行程控制
Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China