zoukankan      html  css  js  c++  java
  • 杭电2012-素数判定

    #include <cstdlib>
    #include <iostream>
    #include<cmath>
    using namespace std;

    //高效判定素数
    bool prime(int n)
    {
         if(n==2)
            return true;
         if(n%2==0)
            return false;
         int sqrtn=(int)sqrt((double)n);
         bool flag=true;
         for(int i=3;i<=sqrtn;i+=2)
            if(n%i==0)
             flag=false;
         return flag;
    }
    int main(int argc, char *argv[])
    {
        int x,y,count;
        while(cin>>x>>y)
        {
           if(x==0&&y==0)
            break;
            count=0;
            for(int i=x;i<=y;i++)
            {
              if(!prime(i*i+i+41))
               count++;
            }
            if(count==0)
              cout<<"OK"<<endl;
            else
              cout<<"Sorry"<<endl;
        }
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  • 相关阅读:
    JPA01
    mybatis入门
    PHP 循环- While循环
    PHP超级全局变量
    PHP 数组排序
    PHP数组
    PHP Switch语句
    PHP IF...Else语句
    PHP运算符
    PHP字符串变量
  • 原文地址:https://www.cnblogs.com/wft1990/p/4322432.html
Copyright © 2011-2022 走看看