当前位置:网站首页>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;
}
边栏推荐
- Mongodb学习篇:安装后的入门第一课
- Application and principle of ThreadPoolExecutor thread pool
- 工业导电滑环的应用
- Copy baby prompt: material cannot be empty. How to solve it?
- 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
- What can the points mall Games bring to businesses? How to build a points mall?
- Spanner 论文小结
- Global and Chinese market of search engine optimization (SEO) software 2022-2028: Research Report on technology, participants, trends, market size and share
- Floweable source code annotation (40) class delegation
猜你喜欢
液压滑环的特点讲解
如何创建一个根据进度改变颜色的进度条
[NLP Li Hongyi] notes
el-cascader回显失败;el-cascader回显不出来
[excel] column operation, which performs specific column for data in a cell, such as text division by comma, colon, space, etc
Understand several related problems in JVM - JVM memory layout, class loading mechanism, garbage collection
Intelligent operation and maintenance: visual management system based on BIM Technology
Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation
Things generated by busybox
如何选择导电滑环材料
随机推荐
基于TI DRV8424驱动步进电机实现调速和行程控制
Simple read / write verification of qdatastream
Causes of short circuit of conductive slip ring and Countermeasures
2/15 (awk, awk conditions, awk processing design can perform additional tasks, and use awk array +for loop to realize advanced search)
使用 Nocalhost 开发 Rainbond 上的微服务应用
Rust基础入门之变量绑定与解构
Application of industrial conductive slip ring
Actual combat: gateway api-2022.2.13
One click deployment of highly available emqx clusters in rainbow
Fiber Bragg grating (FBG) notes [1]: waveguide structure and Bragg wavelength derivation
Day 05 - file operation function
Leetcode316- remove duplicate letters - stack - greedy - string
Application and principle of ThreadPoolExecutor thread pool
More than one file was found with OS independent path ‘lib/armeabi-v7a/libyuv.so‘.
Spanner 论文小结
Introduction to 3D modeling and processing software Liu Ligang University of science and technology of China
液压滑环的特点讲解
Thread process foundation of JUC
Deeply understand the underlying implementation principle of countdownlatch in concurrent programming
El cascade echo failed; El cascader does not echo