当前位置:网站首页>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;
}
};
边栏推荐
- 60 个神级 VS Code 插件!!
- Wechat Emoji is written into the judgment, and every Emoji you send may become evidence in court
- promise async和await的方法与使用
- MCU firmware packaging Script Software
- R language de duplication operation unique duplicate filter
- Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?
- Methods and usage of promise async and await
- 创建型-配置工厂
- Oracle netsuite helps TCM bio understand data changes and make business development more flexible
- ESP32-C3入门教程 问题篇⑨——Core 0 panic‘ed (Load access fault). Exception was unhandled. vfprintf.c:1528
猜你喜欢

Pointdistiller: structured knowledge distillation for efficient and compact 3D detection

Kotlin 协程调度切换线程是时候解开谜团了

“新数科技”完成数千万元A+轮融资,造一体化智能数据库云管理平台

限时预约|6 月 Apache Pulsar 中文开发者与用户组会议

以PolarDB为代表的阿里云数据库以跻身全球第一阵营

60 个神级 VS Code 插件!!

Uncover the whole link communication process of customer service im

EMC surge

R语言查看版本 R包查看版本

Oracle netsuite helps TCM bio understand data changes and make business development more flexible
随机推荐
对象映射 - Mapping.Mapster
揭秘得物客服IM全链路通信过程
Typescript readonlyarray (read only array type) details
Database connection pool Druid
Pointdistiller: structured knowledge distillation for efficient and compact 3D detection
启明星辰集团运维安全网关(堡垒机)再次夺得榜首!
使用cookie技术实现历史浏览记录并控制显示的个数
10 reasons for system performance failure
Alibaba cloud lifeifei: China's cloud database has taken the lead in many mainstream technological innovations abroad
SQL必需掌握的100个重要知识点:汇总数据
“新数科技”完成数千万元A+轮融资,造一体化智能数据库云管理平台
The jetpack compose dropdownmenu is displayed following the finger click position
What is erdma as illustrated by Coptic cartoon?
暑假学习记录
Oracle netsuite helps TCM bio understand data changes and make business development more flexible
EMC-浪涌
ESP32-C3入门教程 基础篇⑪——Non-Volatile Storage (NVS) 非易失性存储参数的读写
相对位置编码Transformer的一个理论缺陷与对策
Line generation (Gauss elimination method, linear basis)
Summer vacation study record