当前位置:网站首页>7-1 are prime numbers
7-1 are prime numbers
2022-06-11 17:38:00 【Tomatoes_ Menon】
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#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;
}
边栏推荐
- Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
- 6-2 多个整数的逆序输出-递归
- Chorus translation
- sql server中移除key lookup书签查找
- Bentley 使用 Authing 快速实现应用系统与身份的集成
- 搜狐全员遭诈骗,暴露哪些问题?
- which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod
- 搜狐全員遭詐騙,暴露哪些問題?
- Activity | authing's first channel cooperation activity came to a successful conclusion
- CentOS7服务器配置(四)---安装redis
猜你喜欢

删除链表的倒数第N个节点---2022/02/22

Read and understand the development plan for software and information technology service industry during the "14th five year plan"
![[online problem] timeout waiting for connection from pool](/img/f0/7e8444ed7d0921b98d5e998e274bc8.png)
[online problem] timeout waiting for connection from pool

为什么udp流设置1316字节

Vscode configures eslint to automatically format with an error "the setting is deprecated. use editor.codeactionsonsave instead with a source“

你还不懂线程池的设计及原理吗?掰开揉碎了教你设计线程池

Bracket generation ---2022/02/25

【深度学习基础】神经网络的学习(3)

Chorus翻译

vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
随机推荐
String to numeric value
合并两个有序链表---2022/02/24
【深度学习基础】神经网络的学习(3)
Delete the penultimate node of the linked list ---2022/02/22
Valid parentheses ---2022/02/23
Use exe4j to convert The jar file is packaged as Exe file
Biden ordered to enforce the zero trust structure
6-8 creating and traversing linked lists
使用exe4j 将.jar文件打包为.exe文件
ffmpeg奇偶场帧Interlace progressive命令和代码处理
开源项目那么多,这次带你了解个版本的区别,明白alpha版、beta版、rc版是什么意思
信息安全数学基础 Chapter 3——有限域(一)
Bentley 使用 Authing 快速实现应用系统与身份的集成
Chorus translation
6-2 写文章(*)
Authing 背后的计算哲学
Authoring share | understanding saml2 protocol
合并K个升序链表---2022/02/26
6-1 read string (*) from file
Speed adjustment of tidb DDL