51nod-【codeforce】A. Vasya and Petya's Game

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.

                

瓦斯亚和皮台亚在玩一个简单的游戏。瓦斯亚心中想一个整数x,它是1到n之间的整数。然后皮台亚尝试着猜这个数字。

皮台亚每次问一个形如这样的问题:这个x是y的倍数吗?

这个游戏的流程是这样的:首先皮台亚把所有他想问的形如上述的问题都问出来(当然他也可以不问任何问题),然后瓦斯亚针对每一个问题给出yes或no的答案。最后皮台亚根据这些问题推断出瓦斯亚心中所想的x是哪个数字。

现在皮台亚想知道他最少要问多少个问题才能猜出1到n之间的那个数字。也就是说不管x是1到n之间的哪个数字只要问那些问题就能够确定那个数字了。

样例解释:

可以问是否是2,3,4这些数字倍数的三个问题。

如果都不是,说明是1.

如果是4的倍数,说明是4.

如果是3的倍数说明是3.

否则就是2。

没有比这更少的问题数目了。

看质因子的种类和个数,k中有几个2 ,3, 5
code:
#include<cstdio>
int a[1000000+11]={0};
int main()
{
	int n;
	scanf("%d",&n);
	    for(int i=2;i<=n;i++)
{
    if(a[i]==0){
    	for(int j=2*i;j<=n;j+=i)
    a[j]++;//表示j同时是2 3 5中几个数的倍数 
	}}
	int num=0;
		for(int i=2;i<=n;i++){
			if(a[i]<2) num++;
		}
		
		printf("%d\n",num);
			for(int i=2;i<=n;i++){
		if(a[i]<2)
		printf("%d ",i);
	}
	return 0;
 } 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值