当前位置:网站首页>Daily question -leetcode1175- permutation of prime numbers - Mathematics
Daily question -leetcode1175- permutation of prime numbers - Mathematics
2022-07-01 04:53:00 【Li Fan, hurry up】
Note:
Prime numbers can be arranged blindly in the position of prime numbers , Non prime numbers can be arranged blindly in the position of non prime numbers , Each is a factorial arrangement
Find out 1 ~ n All prime numbers , Calculate factorials separately , The result multiplied together is the answer
Find the prime number and directly traverse it , Open a table to record whether it is a prime number at present , And how many primes are there to the current position
The code is as follows :
class Solution {
public:
int mod = 1e9 + 7;
int numPrimeArrangements(int n) {
vector<int> list;
int cnt[110];
for(int i = 2; i <= n; i ++){
bool isPrime = true;
for(int j = 2; j * j <= i; j ++){
if(i % j == 0) isPrime = false;
}
if(isPrime) list.push_back(i);
cnt[i] = list.size();
}
long long ans = 1, a = cnt[n], b = n - a;
for(int i = a; i > 1; i --) ans = ans * i % mod;
for(int i = b; i > 1; i --) ans = ans * i % mod;
return (int)ans;
}
};
边栏推荐
- How to use common datasets in pytorch
- Solution: drag the Xib control to the code file, and an error setvalue:forundefined key:this class is not key value coding compliant for the key is reported
- Pico neo3 handle grabs objects
- Matters behind the construction of paint testing laboratory
- 分布式锁的实现
- RuntimeError: “max_pool2d“ not implemented for ‘Long‘
- 缓冲流与转换流
- 对象的序列化与反序列化
- 神经网络-卷积层
- 分布式-总结列表
猜你喜欢

Use and modification of prior network model

神经网络-非线性激活

VIM easy to use tutorial

pytorch 卷积操作

STM32 光敏电阻传感器&两路AD采集

【硬十宝典】——2.【基础知识】开关电源各种拓扑结构的特点

Why is Internet thinking not suitable for AI products?

Distributed transactions - Solutions

分布式架构系统拆分原则、需求、微服务拆分步骤

How to do the performance pressure test of "Health Code"
随机推荐
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
Why is Internet thinking not suitable for AI products?
Single page application
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
Pytorch(四) —— 可视化工具 Visdom
[daily question in summer] Luogu p7222 [rc-04] informatics competition
Thoughts on the construction of Meizhou cell room
Implementation of distributed lock
Several methods of creating thread classes
分布式-总结列表
【暑期每日一题】洛谷 P2637 第一次,第二次,成交!
STM32 extended key scan
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply
神经网络-使用Sequential搭建神经网络
Take a cold bath
Query long transaction
LeetCode_58(最后一个单词的长度)
AssertionError assert I.ndim == 4 and I.shape[1] == 3
