当前位置:网站首页>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;
}

 

 

原网站

版权声明
本文为[Tomatoes_ Menon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111717105400.html