当前位置:网站首页>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;
}
边栏推荐
- Redis database deployment and common commands
- Is there any good website or software for learning programming? [introduction to programming]?
- Detailed explanation of set
- [excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
- More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv. so‘.
- How to traverse massive data in redis
- Things generated by busybox
- One click deployment of highly available emqx clusters in rainbow
- 如何创建一个根据进度改变颜色的进度条
- Speed regulation and stroke control based on Ti drv8424 driving stepper motor
猜你喜欢
Mongodb learning chapter: introduction after installation lesson 1
Typeorm framework
Tcp/ip explanation (version 2) notes / 3 link layer / 3.2 Ethernet and IEEE 802 lan/man standards
液压滑环的特点讲解
Understand several related problems in JVM - JVM memory layout, class loading mechanism, garbage collection
Application of industrial conductive slip ring
LevelDB源码分析之LRU Cache
工业导电滑环的应用
Mongodb学习篇:安装后的入门第一课
Data consistency between redis and database
随机推荐
2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
LevelDB源码分析之LRU Cache
Thread process foundation of JUC
Youqitong [vip] v3.7.2022.0106 official January 22 Edition
Software intelligence: the "world" and "boundary" of AI sentient beings in AAAs system
C WPF uses dockpanel to realize screenshot box
How to select conductive slip ring material
Numeric amount plus comma; JS two methods of adding three digits and a comma to numbers; JS data formatting
CockroachDB 分布式事务源码分析之 TxnCoordSender
[Yugong series] February 2022 Net architecture class 005 ABP vNext Net core web application getting started configuration
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Application of industrial conductive slip ring
Usage and principle of synchronized
Floweable source code annotation (40) class delegation
Mongodb learning chapter: introduction after installation lesson 1
Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
Causes of short circuit of conductive slip ring and Countermeasures
Detailed explanation of set
El cascade echo failed; El cascader does not echo
Unity项目心得总结