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

时间:2023-03-09 04:10:06
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

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
题意:给你一个数n,你给k个数,告诉你整除不整除,用最少的数确定那个数;
思路:根据唯一分解定理,利用素数和素数的次方即可,详见代码;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e2+,M=1e6+,inf=1e9+;\
int prime(int n)
{
if(n<=)
return ;
if(n==)
return ;
if(n%==)
return ;
int k, upperBound=n/;
for(k=; k<=upperBound; k+=)
{
upperBound=n/k;
if(n%k==)
return ;
}
return ;
}
int p[],flag;
int ans[];
int main()
{
int x,y,z,i,t;
flag=;
for(i=;i<;i++)
if(prime(i))
p[flag++]=i;
scanf("%d",&x);
int ji=;
for(i=;i<flag;i++)
{
if(x<p[i])break;
int base=p[i];
while(x>=base)
{
ans[ji++]=base;
base*=p[i];
}
}
printf("%d\n",ji);
for(i=;i<ji;i++)
printf("%d ",ans[i]);
return ;
}