链接: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
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();
}
}

Vasya和Petya正在玩一个猜数字游戏。Vasya想了一个1到n之间的数字,Petya需要通过询问是否能被某些数整除来猜测这个数字。题目要求找出最小的提问数量和应该问哪些数,以确保Petya能确定Vasya的数字。输出包括提问的数量和具体的提问数字。
7827

被折叠的 条评论
为什么被折叠?



