Codeforces Round #319 (Div. 1)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mystery_guest/article/details/70227618

A. Vasya and Petya's Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
4
output
3
2 4 3 
input
6
output
4
2 4 3 5 
Note

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 questions 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以下所有质因数的一次幂,形如Pi,则我们一定不能确定Pi2,P3i,P4i..... 
如果紧接着询问了所有质因数的二次幂,形如P2i,则我们一定不能确定Pi3,P4i....... 
所以经由上面的规律寻找大概猜测我们要询问所有质因子的x次幂,并且该质因子的x次幂小于等于n。 
大概脑补可以想象正确性。 
直接暴力搞就行

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#define eps 1e-8
#define zero(x) (((x>0?(x):-(x))-eps)
#define mem(a,b) memset(a,b,sizeof(a))
#define memmax(a) memset(a,0x3f,sizeof(a))
#define pfn printf("\n")
#define ll __int64
#define ull unsigned long long
#define sf(a) scanf("%d",&a)
#define sf64(a) scanf("%I64d",&a)
#define sf264(a,b) scanf("%I64d%I64d",&a,&b)
#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define sf464(a,b,c,d) scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)
#define sf564(a,b,c,d,ee) scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&ee)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sf5(a,b,c,d,ee) scanf("%d%d%d%d%d",&a,&b,&c,&d,&ee)
#define sff(a) scanf("%f",&a)
#define sfs(a) scanf("%s",a)
#define sfs2(a,b) scanf("%s%s",a,b)
#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)
#define sfd(a) scanf("%lf",&a)
#define sfd2(a,b) scanf("%lf%lf",&a,&b)
#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)
#define sfc(a) scanf("%c",&a)
#define ull unsigned long long
#define pp pair<int,int>
#define debug printf("***\n")
#define pi 3.1415927
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
bool cmpbig(int a, int b){ return a>b; }
bool cmpsmall(int a, int b){ return a<b; }
using namespace std;
int main()
{
   // freopen("data.in","r",stdin);
    //freopen("data.out" ,"w",stdout);
    int n;
    int heshu[1010];
    mem(heshu,0);
    for(int i=2;i*i<=1000;i++)
        for(int j=i;j*i<=1000;j++)
            heshu[i*j]=1;
    while(~sf(n))
    {
        vector<int>flag;
        flag.clear();
        rep(i,2,n+1)
        {
            if(heshu[i])
                continue;
            int p=i;
            while(p<=n)
            {
                flag.push_back(p);
                p*=i;
            }
        }
        cout<<flag.size()<<endl;
        rep(i,0,flag.size())
            cout<<flag[i]<<" ";
        pfn;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/mystery_guest/article/details/70227618