这个题刚开始看的时候是一脸懵逼,不过后来就读懂了,一看这道题就知道这道题是在考素因子分解,他说一个人心中想了一个数让另一个人来猜这个数是啥,求最少的次数和猜的数。换个想法,我们都知道任何一个数都可以分解成一长串素数的乘积。所以,我们只需来求1到n之间的素数种类存下来然后再再对每一个素数挨着去尝试问它的次幂,这样这个数就会花最少的次数猜出来了。
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxm=1e3+10;
int sum[maxm],data[maxm];
int prim(int n)
{
for(int i=2;
i*i<=n;
i++)
{
if(n%i==0)
return 0;
}
return 1;
}
int main()
{
int ans,n,i,j,k,num;
scanf("%d",&n);
ans=0;
num=0;
for(i=2;
i<=n;
i++)
{
if(prim(i))sum[++ans]=i;
}
for(i=1;
i<=ans;
i++)
{
k=sum[i];
while(k<=n)
{
data[++num]=k;
k*=sum[i];
}
}
printf("%d\n",num);
for(i=1;
i<=num;
i++)
{
printf("%d ",data[i]);
}
printf("\n");
return 0;
}
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.
【Vasya and Petya's Game】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