• codeforces #319 C


    C - Vasya and Petya's Game
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.

    Petya can ask questions like: "Is the unknown number divisible by number y?".

    The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.

    Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers yi, he should ask the questions about.

    Input

    A single line contains number n (1 ≤ n ≤ 103).

    Output

    Print the length of the sequence of questions k (0 ≤ k ≤ n), followed by k numbers — the questions yi (1 ≤ yi ≤ n).

    If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.

    Sample Input

    Input
    4
    Output
    3
    2 4 3
    Input
    6
    Output
    4
    2 4 3 5

    Hint

    The sequence from the answer to the first sample test is actually correct.

    If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.

    If the unknown number is divisible by 4, it is 4.

    If the unknown number is divisible by 3, then the unknown number is 3.

    Otherwise, it is equal to 2. Therefore, the sequence of que

    stions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.

    因为每一个正整数可以唯一分解质因数...

    要看能猜多少次,只要知道不大于n的质因子数有多少个即可(相同的算多

    由于n才是1000.所以素数表随便搞就好....不用筛也行...

     1 /*************************************************************************
     2     > File Name: code/cf/#319/C.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年09月18日 星期五 20时29分00秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21 #define y1 hust111qqz
    22 #define yn hez111qqz
    23 #define j1 cute111qqz
    24 #define ms(a,x) memset(a,x,sizeof(a))
    25 #define lr dying111qqz
    26 using namespace std;
    27 #define For(i, n) for (int i=0;i<int(n);++i)  
    28 typedef long long LL;
    29 typedef double DB;
    30 const int inf = 0x3f3f3f3f;
    31 const int N=1E3+5;
    32 int pri[N];
    33 int cnt;
    34 int n;
    35 int ans[N];
    36 bool prime( int x)
    37 {
    38     if (x<=3) return true;
    39     for ( int i = 2 ; i *i <= x ; i++)
    40     {
    41     if (x%i==0) return false;
    42     }
    43     return true;
    44 }
    45 int main()
    46 {
    47   #ifndef  ONLINE_JUDGE 
    48   //  freopen("in.txt","r",stdin); 
    49   #endif
    50     ms(pri,0);
    51     cnt  = 0 ;
    52 
    53     for ( int i = 2 ; i <= 1005 ; i++)
    54     {
    55     if (prime(i))
    56     {
    57         cnt++;
    58         pri[cnt] = i ;
    59     }
    60     }
    61     scanf("%d",&n);
    62     ms(ans,0);
    63     int num = 0 ;
    64     for ( int i = 1 ; pri[i] <= n&&i<=cnt ; i++)
    65     {
    66     int tmp = pri[i];
    67     while (tmp<=n)
    68     {
    69         num++;
    70         ans[num] = tmp;
    71         tmp = tmp * pri[i];
    72         
    73     }
    74     }
    75     cout<<num<<endl;
    76     for ( int i = 1 ; i <= num  ; i++)
    77     {
    78     cout<<ans[i]<<" ";
    79     }
    80 
    81   
    82   
    83  #ifndef ONLINE_JUDGE  
    84   fclose(stdin);
    85   #endif
    86     return 0;
    87 }
    View Code
  • 相关阅读:
    FastDFS概述及原理
    SpringBoot中使用Redis缓存注解
    SpringBoot中使用Redis
    Jedis
    Redis客户端
    Redis的集群配置
    Redis的复制
    英语笔记-5
    内网转发Ubuntu
    数学笔记-4
  • 原文地址:https://www.cnblogs.com/111qqz/p/4820306.html
Copyright © 2020-2023  润新知