Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学题

                                                 C. Vasya and Petya's Game
                                                                                                 time limit per test
                                                                                                 1 second
                                                                                                 memory limit per test
                                                                                                 256 megabytes
 
 

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 test(s)
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,随意拿出一个数,每次你可以提问 x%y==0是否成立,y=(1....n),问你最少提问次数来确定这个任意数是什么

题解:素数必拿出来,素数倍数拿出来存下来就可以了

//1085422276
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define memfy(a) memset(a,-1,sizeof(a))
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define maxn 1001
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
//****************************************


vector<int >v;
int hashs[maxn];
int main()
{
    mem(hashs);
    hashs[1]=1;
    int n=read();
    for(int i=2;i<=n;i++)
    {
        if(hashs[i])continue;
        for(int j=i+i;j<=n;j+=i)
        {
            hashs[j]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(!hashs[i])
            v.push_back(i);
    }
    int sizee=v.size();
    for(int i=0;i<sizee;i++)
    {
        int tmp=v[i];
        while(tmp*v[i]<=n)
        {
            v.push_back(tmp*v[i]);
            tmp=tmp*v[i];
        }

    }
    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}
代码君

 

转载于:https://www.cnblogs.com/zxhl/p/4801045.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值