文章

64

粉丝

53

获赞

3

访问

15.1k

头像
判断素数 题解:
P1013 贵州大学机试题
发布于2024年3月11日 15:52
阅读数 196

1013解题思路

#include <bits/stdc++.h>
 using namespace std;
 

 int sumath(int m)
 {
     int count=0;
     for(int i=2;i<m;i++)
     {
         if(m%i!=0)
         count++;
     }
     if(count==(m-2))
     return m;
     else
     return 0;
 }
 int main()
 {
      int x;
     int y;
     scanf("%d",&x);
     y=sumath(x);
     while(y==0)
     {
         x=x+1;
         y=sumath(x);
      }
      printf("%d",y);
  }
 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发