首页 > 其他分享 >pat1007

pat1007

时间:2023-02-18 21:46:27浏览次数:34  
标签:std 10 main int include pat1007

刚开始打算用数组储存的,总是把问题想得太复杂了。

 1 #include <iostream>
 2 #include <math.h>
 3 #include <stdio.h>
 4 using namespace std;
 5 
 6 bool IsPrime(int m);
 7 int main()
 8 {
 9     int n;
10     scanf("%d",&n);
11     int counts=0;
12     for(int i=4;i<=n;i++)
13     {
14         if(IsPrime(i)&&IsPrime(i-2))
15             counts++;
16     }
17     printf("%d",counts);
18     return 0;
19 }
20 bool IsPrime(int m)
21 {
22     for(int i=2;i<=sqrt(m);i++)
23     {
24         if(m%i==0)
25             return false;
26     }
27     return true;
28 }

 

标签:std,10,main,int,include,pat1007
From: https://www.cnblogs.com/lyhhuster/p/17133688.html

相关文章