A. Vasya and Petya's Game

链接:https://codeforces.com/problemset/problem/576/A

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

扫描二维码关注公众号,回复: 8690004 查看本文章

input

Copy

4

output

Copy

3
2 4 3 

input

Copy

6

output

Copy

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.

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,t,l,r,k,d,ans,max1=0,mod=1e9+7;
long long a[1001],vis[1001],b[1001],x[1001];
queue<long long>q;
bool check(long long y,long long p)
{
	while(y%p==0)
	{
		y/=p;
	}
	if(y==1)
	return true;
	else
	return false; 
}
int main()
{
	cin>>n;
	long long s=0;
	for(int i=2;i<=n;i++)
	{
		if(vis[i]==0)
		{
			s++;
			q.push(i);
			for(int j=2;j*i<=n;j++)
			{
				if(check(j,i))
				{
					s++;
					q.push(j*i);
				}
				vis[j*i]=1;
			}
		}
	}
	cout<<s<<endl;
	while(!q.empty())
	{
		long long x=q.front();
		cout<<x<<" ";
		q.pop();
	}
	
} 
发布了137 篇原创文章 · 获赞 15 · 访问量 9906

猜你喜欢

转载自blog.csdn.net/Luoriliming/article/details/104016034
今日推荐