当前位置:网站首页>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;
}
};
边栏推荐
- Esp32-c3 introductory tutorial question ⑨ - core 0 panic 'ed (load access fault) Exception was unhandled. vfprintf. c:1528
- QT embeds the sub QT program window into the current program
- Summer vacation study record
- SQL必需掌握的100个重要知识点:汇总数据
- 14岁懂社会-《关于“工作的幸福”这件事儿》读书笔记
- 优惠券种类那么多,先区分清楚再薅羊毛!
- Evaluation of IP location query interface Ⅲ
- 100 important knowledge points that SQL must master: join table
- 林克庆到番禺区调研“发展要安全”工作 以“时时放心不下”责任感抓好安全发展各项工作
- 华三交换机清空配置
猜你喜欢

The first China Digital Collection conference will be held soon

Uncover the whole link communication process of customer service im

Multiparty Cardinality Testing for Threshold Private Set-2021:解读

Alibaba cloud database represented by polardb ranks first in the world

【IC5000教程】-01-使用daqIDEA图形化debug调试C代码

Jetpack Compose DropdownMenu跟随手指点击位置显示

Go language defer
![[understanding of opportunity -34]: fate is within the light cone](/img/3e/9f5630ba382df7f7ce00705445cef8.jpg)
[understanding of opportunity -34]: fate is within the light cone

Handler-源码分析

CVPR 2022 | greatly reduce the manual annotation required for zero sample learning. Mapu and Beiyou proposed category semantic embedding rich in visual information
随机推荐
The life, working principle and application of electrochemical oxygen sensor
据说用了这个,老板连夜把测试开了
SQL必需掌握的100个重要知识点:使用子查询
Multiparty Cardinality Testing for Threshold Private Set-2021:解读
The jetpack compose dropdownmenu is displayed following the finger click position
Go语言学习之Switch语句的使用
100 important knowledge points that SQL must master: using stored procedures
Line generation (Gauss elimination method, linear basis)
Database connection pool Druid
Esp32-c3 introductory tutorial basic part ⑪ - reading and writing non-volatile storage (NVS) parameters
数据库 自动增长
Object mapping - mapping Mapster
华三交换机清空配置
[untitled]
How to 'gracefully' avoid MySQL login prompt information in scripts
限时预约|6 月 Apache Pulsar 中文开发者与用户组会议
It's time for the kotlin coroutine to schedule thread switching to solve the mystery
100 important knowledge points that SQL must master: join table
Jetpack Compose DropdownMenu跟随手指点击位置显示
Filter error in dplyr: can't transform a data frame with duplicate names