当前位置:网站首页>1175. prime permutation
1175. prime permutation
2022-06-30 11:40:00 【anieoo】
Original link :1175. Permutation of prime numbers
solution:
Calculate the number of prime and non prime numbers , Then calculate the number of methods by permutation and combination
const int mod = 1e9 + 7;
class Solution {
public:
int numPrimeArrangements(int n) {
int cnt_p = 0,cnt_o = 0; // Save the number of prime and non prime numbers
for(int i = 2;i <= n;i++) {
if(isprime(i)) cnt_p++;
}
cnt_o = n - cnt_p;
long long res = 1; // Return value
for(int i = 1;i <= cnt_p;i++)
res = res * i % mod;
for(int i = 1;i <= cnt_o;i++)
res = res * i % mod;
return (int)res;
}
// To judge whether a number is a prime number
bool isprime(int x) {
for(int i = 2;i <= x / i;i++) {
if(x % i == 0) return false;
}
return true;
}
};
边栏推荐
- 创建型-配置工厂
- 基于视觉的机器人抓取:从物体定位、物体姿态估计到平行抓取器抓取估计
- Database cascading operation
- Dameng data rushes to the scientific innovation board, or becomes the "first share of domestic database" in the A-share market
- Summer vacation study record
- Create - configure factory
- AMS源码解析
- Database transactions
- A theoretical defect of relative position coding transformer and Its Countermeasures
- datax - 艰难debug路
猜你喜欢
随机推荐
HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴
8 lines of code to achieve quick sorting, easy to understand illustrations!
压缩状态DP位运算
Discussion on the essence of "FPGA mining" from open source projects
HMS core audio editing service 3D audio technology helps create an immersive auditory feast
Line generation (Gauss elimination method, linear basis)
How to 'gracefully' avoid MySQL login prompt information in scripts
The operation and maintenance security gateway (Fortress machine) of Qiming star group once again won the first place!
以PolarDB为代表的阿里云数据库以跻身全球第一阵营
【IC5000教程】-01-使用daqIDEA图形化debug调试C代码
100 important knowledge points that SQL must master: using subquery
14岁懂社会-《关于“工作的幸福”这件事儿》读书笔记
Set up your own website (13)
Typescript readonlyarray (read only array type) details
Filter error in dplyr: can't transform a data frame with duplicate names
数字化不是试出来,而是蹚出来的|行知数字中国 × 富士康史喆
学习redis实现分布式锁—–自己的一个理解
100 important knowledge points that SQL must master: insert data
100 important knowledge points that SQL must master: Combined Query
Summer vacation study record








