zoukankan      html  css  js  c++  java
  • HDU2161 Primes

     1 /*
     2  HDU2161 Primes
     3  http://acm.hdu.edu.cn/showproblem.php?pid=2161
     4  数论 水题
     5  注意输入截止条件是n<=0
     6  */
     7 #include <cstdio>
     8 #include <algorithm>
     9 #include <cstring>
    10 #include <cmath>
    11 #include <vector>
    12 #include <queue>
    13 //#define test
    14 using namespace std;
    15 const int Nmax=16005;
    16 int is_prime[Nmax];
    17 void get()
    18 {
    19     for(int i=2;i<Nmax;i++)
    20         is_prime[i]=1;
    21     for(int i=2;i<Nmax;i++)
    22     {
    23         if(is_prime[i])
    24         {
    25             for(int j=2;j*i<Nmax;j++)
    26                 is_prime[i*j]=0;
    27         }
    28     }
    29     is_prime[2]=0;
    30 }
    31 int main()
    32 {
    33     #ifdef test
    34     #endif
    35     int n,t=0;
    36     get();
    37     while(scanf("%d",&n)==1)
    38     {
    39         if(n<=0)
    40             break;
    41         t++;
    42         printf("%d: ",t);
    43         if(is_prime[n])
    44             printf("yes
    ");
    45         else
    46             printf("no
    ");
    47     }
    48  
    49     return 0;
    50 }
  • 相关阅读:
    Windows Vs2010 + Qt5
    Java基础1
    关键字volatile
    内联函数
    Const详解2
    模板特化
    引用
    旧代码中的"enum hack"
    angularjs之ngoption
    angularjs之向下一个页面传参
  • 原文地址:https://www.cnblogs.com/BBBob/p/6641679.html
Copyright © 2011-2022 走看看