We'll call a set of positive integers a beautiful if the following condition fulfills: for any prime p, if , then . In other words, if one number from the set is divisible by prime p, then at least half of numbers from the set is divisible by p.
Your task is to find any beautiful set, where the number of elements is equal to k and each element doesn't exceed 2k2.
InputThe first line contains integer k (10 ≤ k ≤ 5000) that shows how many numbers the required beautiful set should have.
OutputIn the first line print k space-separated integers that are a beautiful set. If there are multiple such sets, you are allowed to print any of them.
Examples input 10 output 16 18 24 27 36 48 54 72 108 144题目链接:http://codeforces.com/contest/364/problem/C
这场比赛绝了,abc三个题都没做出来。我是不是有点太菜了。。。
http://vawait.com/2013/11/codeforces-364c/
还需要继续学习这个题。
代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long lint; int a[8]={0,2,3,5,7,11,13,17}; int n,m,ans[1000000],s,ma; void init(){ cin>>n; ma=n*n*2; } void dfs(int t,int k){ if(t>m){ ans[s++]=k; return; } dfs(t+1,k); while(k*a[t]<=ma){ k*=a[t]; dfs(t+1,k); } } void work(){ for(int i=2;i<=6;i++){ m=i; s=0; dfs(1,1); if(s<2*n) continue; sort(ans,ans+s); for(int j=1;j<=n-1;j++) printf("%d ",ans[s-j]); printf("%d\n",ans[s-n]); break; } } int main(){ init(); work(); return 0; }