• Semi-Prime(set)


    Prime Number Definition 
    An integer greater than one is called a prime number if its only positive divisors (factors) are one and itself. For instance, 2, 11, 67, 89 are prime numbers but 8, 20, 27 are not.

    Semi-Prime Number Definition 
    An integer greater than one is called a semi-prime number if it can be decompounded to TWO prime numbers. For example, 6 is a semi-prime number but 12 is not.

    Your task is just to determinate whether a given number is a semi-prime number.

    素数定义

    如果一个大于1的整数只有一个正整数(因子)是一个整数,那么它就称为素数。 例如,2,11,67,89是素数,但8,20,27不是。

    半素数定义

    如果一个大于1的整数可以分解为两个素数,则称其为一个半素数。 例如,6是一个半素数,但12不是。

    你的任务只是确定一个给定的数字是否是一个半素数。

    Input

    There are several test cases in the input. Each case contains a single integer N (2 <= N <= 1,000,000)

    输入中有几个测试用例。 每个案例包含一个整数N(2 <= N <= 1,000,000)

    Output

    One line with a single integer for each case. If the number is a semi-prime number, then output "Yes", otherwise "No".

    一行每个案件都有一个整数。 如果数字是半素数,则输出“是”,否则输出“否”。

    Sample Input

    3
    4
    6
    12

    Sample OutputNo 
    Yes 
    Yes 
    No 

    what i have learned:

    set search

     1 #include<iostream>
     2 #include<vector>
     3 #include<set>
     4 #include<cmath>
     5 using namespace std;
     6 
     7 vector<int> v;
     8 set<int> s;
     9 
    10 void pt(int a, int b)
    11 {
    12     for(int i = a; i <= b; i++)
    13     {
    14         if(i != 2 && i % 2 == 0)
    15             continue;
    16         for(int j = 3; j * j <= i; j += 2)
    17         {
    18             if(i % j == 0)
    19                 goto RL;
    20         }
    21         v.push_back(i);
    22         RL: continue;
    23     }
    24 }
    25 
    26 int main()
    27 {
    28     pt(2, 500000);
    29     int i, j, p;
    30     for(int i = 0; i < v.size(); i++)
    31     {
    32         for(int j = 0; j < v.size(); j++)
    33         {
    34             p = v[i] * v[j];
    35             if(p < 1000000)
    36                 s.insert(p);
    37             else
    38                 break;
    39         }
    40     }
    41 
    42     int n;
    43     set<int>::iterator it;
    44     while(cin >> n)
    45     {
    46         it = s.find(n);
    47         if(it != s.end())
    48             cout << "Yes" << endl;
    49         else
    50             cout << "No" << endl;
    51     }
    52     return 0;
    53 }
    View Code
    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    开发两年!JVM方法调用都玩不明白,你离被炒鱿鱼不远了!
    springboot基本框架搭建零基础教程,对新手极为友好!
    SpingBoot整合Mybatis,这些小技巧你得知道,对你工作有很大的帮助!
    今天我们基于jdk8聊聊JVM-常量池,希望对大家有帮助!
    剑指 Offer 12. 矩阵中的路径
    WUSTCTF2020 funnyre
    2020 DJBCTF RE wp
    黑马c++基础的一个通讯录系统
    elf文件结构解读以及plt节got节的理解
    ubuntu16.04上编译android的可执行文件并调用本地so库
  • 原文地址:https://www.cnblogs.com/h-hkai/p/8666285.html
Copyright © 2020-2023  润新知