当前位置:网站首页>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;
}
};
边栏推荐
- [une question par jour pendant l'été] course luogu p1568
- C read / write application configuration file app exe. Config and display it on the interface
- LeetCode_66(加一)
- 1076 Forwards on Weibo
- RDF query language SPARQL
- Pytorch(四) —— 可视化工具 Visdom
- [FTP] common FTP commands, updating continuously
- Leecode question brushing record 1310 subarray XOR query
- C -- array
- [daily question in summer] function of rogu p3742 UMI
猜你喜欢

Neural network convolution layer

Technology sharing | broadcast function design in integrated dispatching

How to do the performance pressure test of "Health Code"

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

Neural networks - use sequential to build neural networks

神经网络-卷积层

Dede collection plug-in does not need to write rules

The longest increasing subsequence and its optimal solution, total animal weight problem
![解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *](/img/88/0b99d1db2cdc70ab72d2b3c623dfaa.jpg)
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *

分布式-总结列表
随机推荐
手动实现一个简单的栈
Basic exercise of test questions hexadecimal to decimal
先有网络模型的使用及修改
C - detailed explanation of operators and summary of use cases
C read / write application configuration file app exe. Config and display it on the interface
Pytorch neural network construction template
Pytest automated testing - compare robotframework framework
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
Why is Internet thinking not suitable for AI products?
Principle, technology and implementation scheme of data consistency in distributed database
【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛
AssertionError assert I.ndim == 4 and I.shape[1] == 3
Serialization and deserialization of objects
洗个冷水澡吧
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
Oracle views the creation time of the tablespace in the database
Neural networks - use of maximum pooling
Codeforces Round #771 (Div. 2) ABCD|E
Basic skeleton of neural network nn Use of moudle
RDF query language SPARQL
