zoukankan      html  css  js  c++  java
  • HDU2161 Primes

      这里主要预习了素数筛选以及输入外挂的编写。涛神的筛选法一直记着,给力。

      

    #include <cstdio>
    #include
    <cstring>
    #include
    <cstdlib>
    using namespace std;

    char hash[16005] = {0};

    bool getint( int &t )
    {
    char c; int f = 1;
    while( c = getchar(), c != '-' && ( c < '0' || c > '9' ) )
    {
    if( c == EOF )
    return false;
    }
    if( c == '-' )
    f
    = -1;
    else
    t
    = c - '0';
    while( c = getchar(), c >= '0' && c <= '9' )
    t
    = t * 10 + c -'0';
    t
    *= f;
    return true;
    }

    int main()
    {
    hash[
    1] = 1;
    for( int i = 2; i <= 16000; i += 2 )
    hash[i]
    = 1;
    for( int i = 3; i <= 301; ++i )
    {
    int k = 2 * i;
    for( int j = i * i; j <= 16000; j += k )
    {
    hash[j]
    = 1;
    }
    }
    int N, t = 1;
    while( getint( N ), N> 0 )
    {
    printf( hash[N]
    ? "%d: no\n" : "%d: yes\n", t );
    t
    ++;
    }
    return 0;
    }

      

  • 相关阅读:
    读取声音文件的方法
    在MAC电脑上抓取iphone数据包的方法
    Mac+IPAD上使用wireshark抓包
    2020/7/24
    2020牛客多校第二场01,05题
    2020/7/23
    2020/7/22
    2020/7/20
    2020/7/19
    2020/7/18
  • 原文地址:https://www.cnblogs.com/Lyush/p/2158874.html
Copyright © 2011-2022 走看看