当前位置:网站首页>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;
}
边栏推荐
- Activity | authing's first channel cooperation activity came to a successful conclusion
- Vscode configures eslint to automatically format an error "auto fix is enabled by default. use the single string form“
- A set of ThinkPHP wechat applet mall source code with background management
- 活动 | Authing 首次渠道合作活动圆满落幕
- GemBox. Bundle 43.0 Crack
- [pytest learning] after the pytest case fails to execute, the others will not be executed
- A simple understanding of closures
- GUI guess number game, directly open play
- threejs中设置物体的贴图+场景的6面贴图 +创建空间
- JPA循环保存多个实体失败
猜你喜欢

Read and understand the development plan for software and information technology service industry during the "14th five year plan"
![[Clickhouse column] create a new library, user and role](/img/e5/d11493a37e25b7dde6cc43b3828749.png)
[Clickhouse column] create a new library, user and role

C language: use H and C. summary of problems encountered in documents

MATLAB中histogram函数的使用

Authing Share|理解 SAML2 协议

05_特征工程—降维

Docker安装mysql5.7(开启binlog功能、修改字符)

Activity | authing's first channel cooperation activity came to a successful conclusion

二级造价工程师值得考吗?发展前景如何?

你还不懂线程池的设计及原理吗?掰开揉碎了教你设计线程池
随机推荐
Guide to Dama data management knowledge system: percentage of chapter scores
Tornado environment construction and basic framework construction -- familiar Hello World
How to simplify a lot of if... Elif... Else code?
LeetCode-1005. Maximized array sum after K negations
使用exe4j 将.jar文件打包为.exe文件
10 times faster than 5g. Are you ready for 10 Gigabit communication?
LeetCode-1005. K 次取反后最大化的数组和
说说集合的面试题
vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
API management artifact that allows you to call wow directly
Is the second-class cost engineer worth the exam? What is the development prospect?
ASP. Net education OA system source code education industry OA system source code with document
我的CのERROR们
搜狐全員遭詐騙,暴露哪些問題?
端口规划与APJ
TestPattern error
My C の errors
从制造到“智造”,探索制造企业破局之道
QLineEdit 设置输入掩码
Don't you understand the design and principle of thread pool? Break it up and crush it. I'll teach you how to design the thread pool