C. Beautiful Set----枚举

C. Beautiful Set
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains integer k (10 ≤ k ≤ 5000) that shows how many numbers the required beautiful set should have.

Output

In 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值