当前位置:网站首页>1175. 质数排列
1175. 质数排列
2022-06-30 11:09:00 【anieoo】
原题链接:1175. 质数排列
solution:
计算出质数和非质数的个数,再通过排列组合计算出方法数
const int mod = 1e9 + 7;
class Solution {
public:
int numPrimeArrangements(int n) {
int cnt_p = 0,cnt_o = 0; //保存质数和非质数的个数
for(int i = 2;i <= n;i++) {
if(isprime(i)) cnt_p++;
}
cnt_o = n - cnt_p;
long long res = 1; //返回值
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;
}
//判断一个数是不是质数
bool isprime(int x) {
for(int i = 2;i <= x / i;i++) {
if(x % i == 0) return false;
}
return true;
}
};
边栏推荐
- Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?
- [untitled]
- Oracle NetSuite 助力 TCM Bio,洞悉数据变化,让业务发展更灵活
- CVPR 2022 | greatly reduce the manual annotation required for zero sample learning. Mapu and Beiyou proposed category semantic embedding rich in visual information
- 压缩状态DP位运算
- CVPR 2022 | 大幅减少零样本学习所需人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入...
- AMS source code analysis
- Oceanbase installation Yum source configuration error and Solutions
- 线代(高斯消元法、线性基)
- Is the golden cycle of domestic databases coming?
猜你喜欢

阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外

Digitalization is not a trial, but a wading out of "Xingzhi Digital China" × History of Foxconn

Object mapping - mapping Mapster

孔松(信通院)-数字化时代云安全能力建设及趋势

暑假学习记录

Evaluation of IP location query interface Ⅲ

Summer vacation study record

EMC surge

win10 R包安装报错:没有安装在arch=i386
![[understanding of opportunity -34]: fate is within the light cone](/img/3e/9f5630ba382df7f7ce00705445cef8.jpg)
[understanding of opportunity -34]: fate is within the light cone
随机推荐
Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?
100 important knowledge points that SQL must master: using stored procedures
SQL必需掌握的100个重要知识点:使用视图
100 important knowledge points that SQL must master: using subquery
EMC surge
建立自己的网站(13)
Alibaba cloud lifeifei: China's cloud database has taken the lead in many mainstream technological innovations abroad
The first batch in China! Alibaba cloud native data Lake products have passed the evaluation and certification of the ICT Institute
SQL必需掌握的100个重要知识点:使用表别名
暑假学习记录
Shutter from zero 004 button assembly
Kongsong (ICT Institute) - cloud security capacity building and trend in the digital age
Xu Lei expressed three thanks for the most difficult 618 in 19 years
脚本中如何'优雅'避免MySQL登录提示信息
数据库 自动增长
100 important knowledge points that SQL must master: Combined Query
Create - configure factory
MCU firmware packaging Script Software
揭秘得物客服IM全链路通信过程
Is the golden cycle of domestic databases coming?