zoukankan      html  css  js  c++  java
  • SDNU 1246.prime

    这道题是很简单的题,我本来想用埃氏筛来解决,结果发现内存太大,爆掉了;就换了比较简单的办法去求;

    这个故事告诉我们,这道题不能用埃氏筛。

    Description

     This is a verrrrrrrrrry easy problem, when Lulichuan was a freshman, he can ease to judge whether a number is a prime, there some TestCase, you just need to judge if the number is a prime, if it’s a prime output  “N”, else output “Y

    Input

    The first line is T(0 < T < 100000)

    Then follow T line, every line is a number n(0 < n <100000000)

    Output

    As stated in the title

    Sample Input

     5
     1
     2
     3
     4
     5

    Sample Output

     Y
     N
     N
     Y
     N
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    int main()
    {
        int n;
        while(~scanf("%d", &n))
        {
            for(int i = 0; i < n; ++i)
            {
                int a;
                scanf("%d", &a);
                if(a == 1)
                {
                    cout << 'Y' << '
    ';
                    continue;
                }
                int j;
                for(j = 2; j <= sqrt(a); ++j)
                {
                    if(a % j == 0)
                        break;
                }
                if(j > sqrt(a))
                    cout << 'N' << '
    ';
                else
                    cout << 'Y' << '
    ';
            }
        }
        return 0;
    }
  • 相关阅读:
    如何使用API创建OpenStack虚拟机?
    Windows Server 2012 新特性:IPAM的配置
    DNSSec
    Win Server 8中的利器:微软在线备份服务
    AD RMS总结
    开发中辅助功能
    开发中坑爹的地方
    Js 中常用方法
    asp.net 错误处理
    js中的注意事项(持续整理)
  • 原文地址:https://www.cnblogs.com/RootVount/p/10370970.html
Copyright © 2011-2022 走看看