C. Vasya and Petya's Game
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/577/problem/C
Description
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.
Sample Input
4
Sample Output
3
2 4 3
HINT
题意
在1-n中随便选一个数,然后你可以提问,问这个数是否%y==0
问你最少问多少次,可以确定这个数
题解:
假设,你没有问p^k(p是素数,k>1),那么你是不能够分辨p^k-1 和p^k的
所以你就必须问咯
所以最后答案只需要把小于等于n的素数以及素数的幂都输出出来就好了
代码:
//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 500001
#define mod 1001
#define eps 1e-9
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//*************************************************************************************
vector<int> ans;
vector<int> Q;
int main()
{
int n=read();
if(n==)
{
printf("");
return ;
}
for(int i=;i<=n;i++)
{
int flag = ;
for(int j=;j*j<=i;j++)
{
if(i%j)continue;
flag=;break;
}
if(!flag)ans.push_back(i);
}
for(int i=;i<ans.size();i++)
{
int j = ans[i];
for(;j<=n;j*=ans[i])
Q.push_back(j);
}
printf("%d\n",Q.size());
for(int i=;i<Q.size();i++)
printf("%d ",Q[i]);
printf("\n");
}