码迷,mamicode.com
首页 > 其他好文 > 详细

2012.素数判定

时间:2018-10-01 21:07:38      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:cin   prime   nbsp   strong   return   mat   clu   std   ==   

#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.素数判定

标签:cin   prime   nbsp   strong   return   mat   clu   std   ==   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!