当前位置:网站首页>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;
}
边栏推荐
- Usage and principle of synchronized
- Set集合詳細講解
- Memtable for leveldb source code analysis
- QDataStream的簡單讀寫驗證
- Summary of common components of applet
- More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv. so‘.
- [RootersCTF2019]babyWeb
- Daily code 300 lines learning notes day 11
- [RootersCTF2019]babyWeb
- 3D建模與處理軟件簡介 劉利剛 中國科技大學
猜你喜欢

基于TI DRV8424驱动步进电机实现调速和行程控制

Use and principle of wait notify

One click deployment of highly available emqx clusters in rainbow

ssm+mysql二手交易网站(论文+源码获取链接)

LevelDB源码分析之memtable

Tar command

What is the at instruction set often used in the development of IOT devices?

Vmware workstation network card settings and three common network modes

Data consistency between redis and database

Ssm+mysql second-hand trading website (thesis + source code access link)
随机推荐
Application of industrial conductive slip ring
Design and application of immutable classes
One click deployment of highly available emqx clusters in rainbow
Precautions for use of conductive slip ring
Use and principle of reentrantlock
Summary of spanner's paper
TypeORM 框架
新手在挖财开通证券账户安全吗?
Flutter 实现每次进来界面都刷新数据
In depth understanding of condition source code interpretation and analysis of concurrent programming
Spanner 论文小结
Is it safe for a novice to open a securities account?
2022.6.30-----leetcode.1175
Thread process foundation of JUC
3D建模与处理软件简介 刘利刚 中国科技大学
Data governance: data governance framework (Part I)
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Day 05 - file operation function
Intelligent operation and maintenance: visual management system based on BIM Technology
Mathematical knowledge: finding the number of divisors