当前位置:网站首页>7-1 均是素数
7-1 均是素数
2022-06-11 17:17:00 【西红柿_码农】
在给定的区间 [m,n] 内,是否存在素数 p、q、r(p<q<r),使得 pq+r、qr+p、rp+q 均是素数?
输入格式:
输入给出区间的两个端点 0<m<n≤1000,其间以空格分隔。
输出格式:
在一行中输出满足条件的素数三元组的个数。
输入样例:
1 35
输出样例:
10
样例解读
满足条件的 10 组解为:
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#include<stdio.h>
#include<math.h>
int judge(int m)
{
if (m < 2)
return 0;
for (int i = 2; i <= sqrt(m); i++)
{
if (m % i == 0)
return 0;
}
return 1;
}
int main()
{
int m, n;
int arr[1001];
scanf("%d%d", &m, &n);
int j = 0, flag = 0;
for (int i = m; i <= n; i++)
{
if (judge(i) == 1)
{
arr[j] = i;
j++;
}
}
int x = 0;
for (int p = 0; p < j; p++)
{
for (int q = p + 1; q < j; q++)
{
for (int r = q + 1; r < j; r++)
{
if (judge(arr[p] * arr[q] + arr[r]) == 1 && judge(arr[q] * arr[r] + arr[p]) == 1 && judge(arr[r] * arr[p] + arr[q]) == 1) {
x++;
}
}
}
}
printf("%d\n", x);
return 0;
}
边栏推荐
- 为什么udp流设置1316字节
- Intranet penetration based on UDP port guessing
- 如何成为一个乐观派组织?
- JPA failed to save multiple entities circularly
- av_read_frame返回值为-5 Input/output error
- ffmpeg CBR精准码流控制三个步骤
- which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod
- Bentley 使用 Authing 快速实现应用系统与身份的集成
- Hands on deep learning - multiple input and output channels in the convolution layer
- [pytest learning] after the pytest case fails to execute, the others will not be executed
猜你喜欢

Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单

活动 | Authing 首次渠道合作活动圆满落幕

QLineEdit 设置输入掩码

Analysis report on competition pattern and future development strategy of China's corn industry 2022-2028 Edition

ffmpeg硬件编解码Nvidia GPU

Is the second-class cost engineer worth the exam? What is the development prospect?

Connect the server with springboard / fortress through xshell

05_特征工程—降维

Leetcode力扣刷题

vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
随机推荐
Song of the sea in 5g Era
用实际案例分析PMP与ACP应该考哪个?哪个更有用?
CS0006 C# 未能找到元数据文件“C:\Users\...问题
10 times faster than 5g. Are you ready for 10 Gigabit communication?
LeetCode-859. 亲密字符串
Vscode configures eslint to automatically format with an error "the setting is deprecated. use editor.codeactionsonsave instead with a source“
JSP page initial loading method
Dynamic: capturing network dynamics using dynamic graph representation learning
拜登下令强制推行零信任架构
threejs中设置物体的贴图+场景的6面贴图 +创建空间
6-2 写文章(*)
你还不懂线程池的设计及原理吗?掰开揉碎了教你设计线程池
LeetCode-1005. K 次取反后最大化的数组和
From manufacturing to "intelligent manufacturing", explore the way for manufacturing enterprises to break the situation
A simple understanding of closures
Authing biweekly news: online application market (5.10-5.22)
Haas, which integrates relevant technologies of Alibaba cloud, Dharma Institute and pingtouge, has officially announced the book
Leetcode-- array
闭包的简单理解
Hands on deep learning - multiple input and output channels in the convolution layer