当前位置:网站首页>All primes - ladder training competition
All primes - ladder training competition
2022-04-22 02:34:00 【MITBlick】
L1-8 Are prime numbers (20 branch )
In a given interval [m,n] Inside , Is there a prime p、q、r(p<q<r), bring pq+r、qr+p、rp+q Are prime numbers ?
Input format :
Enter the two endpoints of the given interval 0<m<n≤1000, Separated by spaces .
Output format :
Output the number of prime triples that meet the conditions in one line .
sample input :
1 35
sample output :
10
Example interpretation
Satisfied 10 Group solution is :
2, 3, 5
2, 3, 7
2, 3, 13
2, 3, 17
2, 5, 7
2, 5, 13
2, 5, 19
2, 5, 31
2, 7, 23
2, 13, 17
How to solve the problem : If this question uses a linear sieve to judge each number one by one , There will be a timeout , So this question adopts a more advanced method Euler screen .
Code:
#include <iostream>
#include <stdio.h>
using namespace std;
const int N = 1000010;
int n, m, p, q, r, ans;
bool f[N];
void prime() // Euler screen main part
{
for(int i = 2; i <= 1000; i ++ )
{
if(!f[i])
{
for(int j = 2; i * j <= 1000010; j ++ )
{
if(!f[i * j]) f[i * j] = true;
}
}
}
}
signed main()
{
f[1] = true;
prime();
cin >> n >> m;
for(int i = n; i <= m; i ++ )
{
for(int j = i + 1; j <= m; j ++ )
{
for(int k = j + 1; k <= m; k ++ )
{
if(!f[i] && !f[j] && !f[k] && !f[i * j + k] && !f[i * k + j] && !f[j * k + i]) ans ++;
}
}
}
cout << ans << endl;
}
版权声明
本文为[MITBlick]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211422547116.html
边栏推荐
- The flitter does not use the navigation bar of the status bar
- 刷题计划——动态规划dynamic programming(一)
- Database case section
- The shortcut key for modifying the drawing board size of illustrator (AI) is shift + O by default
- Software testing · bad taste
- 循环链表的创建及可控输出
- Analysis of header NAT & DHCP protocol
- K3s source code analysis 2 - Master Logic source code analysis
- 吴恩达机器学习作业——逻辑回归
- Can initialization process
猜你喜欢

In PostgreSQL, convert a string to an integer or floating-point type in the query result

我靠,有人在我的代码注释里的“下毒”?

Scala installation and environment configuration

Complete solution of closure operation in Discrete Mathematics
![[※ leetcode refers to the path in offer 12. Matrix (simple)]](/img/88/2c1c7a9954d824495f0b99223ce7fc.png)
[※ leetcode refers to the path in offer 12. Matrix (simple)]

Explain the mathematical process of neural network like a pile of LEGO

(进阶)C函数调用

uniapp实现出生日期/时间选择效果

创建双向链表(详解)

Explain various cloud computing models in detail. How can enterprises use each model to improve business productivity?
随机推荐
How does ECS connect to ad domain or LDAP user source
[Xiao Yang takes you to play with C language] circular structure (detailed explanation)
刷题计划——动态规划dynamic programming(二)
2022年物联网安全的发展趋势
softmax运算
&lt; Translation & gt; Set up Prometheus and integrate it with grafana for monitoring
AI应用说-智慧农场(牛场无人监控)
Analysis and interpretation of the current situation and challenges faced by enterprise operation and maintenance in the digital era
AI application theory - Smart farm (cattle farm without monitoring)
创建双向链表(详解)
CentOS 7 installs mysql5 7 detailed tutorial
Information Security Overview
Excel tips - vlookup automatic matching
【※ LeetCode 剑指 Offer 13. 机器人的运动范围(简单)】
Another way to write the fluent interface is to write a part first, then material, and put the method body in the method body
Explain various cloud computing models in detail. How can enterprises use each model to improve business productivity?
WSOLA原理及matlab仿真
STM32 flash operation
error:there‘s no Qt version assigned to project please assign a Qt installation in qt project settin
Scala installation and environment configuration