首页 > 其他 > 详细

2012.素数判定

时间:2018-10-01 21:03:32      阅读:204      评论:0      收藏:0      [点我收藏+]

#include<iostream>

#include<math.h>

using namespace std;

 

int is_prime(int p){

         int j,k=0;

         for(j=2;j<=p;j++){

                   if(p%j!=0)k++;

                   break;

         }

         if(k==0)return 0;

         else return 1;

}

int main(){

int m,n,i,f;

cin>>m>>n;

if(m==0&&n==0)cout<<"end"<<endl;

if(m>n){

         int temp=n;n=m;m=temp;

}

for(i=m;i<=n;i++){

        int p=i*i+i+41;          

    if(is_prime(p)==0){

             f=0;

             break;

         }

         if(f=0)cout<<"Sorry"<<endl;

         else cout<<"OK"<<endl;}

system("pause");

return 0;

}

2012.素数判定

原文:https://www.cnblogs.com/huoyuying/p/9735688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!