• codeforce364(div1.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 

     思路:贪心+dfs;

    因为每个出现的素数都要在集合中至少有(n+1)/2个与他不互质的数,你可以发现所有的素数都小于17,那么也就是那些数最多就会由6个素数构成,那么我们每次贪心优先选每个素数都是那个数的因子的数就行,还有选数不能超过某个范围,所以我们先以某个数结尾,从小到大dfs找到那个至少有n个数的那个结束的素数,然后以他结尾再dfs一遍取前n个数就是答案。

     1 #include<stdio.h>
     2 #include<algorithm>
     3 #include<stdlib.h>
     4 #include<iostream>
     5 #include<string.h>
     6 #include<queue>
     7 #include<math.h>
     8 typedef long long LL;
     9 using namespace std;
    10 LL prime[7]= {2,3,5,7,11,13};
    11 LL  ans[10000];
    12 LL  ak=0;
    13 LL N;
    14 LL v;
    15 int flag[7];
    16 int maxx_fl[7];
    17 void dfs(LL top,LL d,LL ap,bool fla)
    18 {     if( ap > 2*v*v)return ;
    19        else  if(d == -1&&fla)
    20         {
    21                 int i,j;
    22                 ans[ak++]=ap;
    23                 return ;
    24         }
    25         else if(d == -1)
    26         {
    27                ak++;
    28                return ;
    29         }
    30 
    31         else
    32         {
    33                 LL  cf=top;
    34                 LL as=ap;
    35                 while(cf > prime[d])
    36                 {
    37                         cf /= prime[d];
    38                         as *= prime[d];
    39                         flag[d]++;
    40                         dfs(cf,d-1,as,fla);
    41                 }
    42                 dfs(top,d-1,ap,fla);
    43         }
    44 }
    45 int main(void)
    46 {
    47         LL n;
    48         while(scanf("%I64d",&n)!=EOF)
    49         {
    50                 memset(flag,0,sizeof(flag));
    51                 LL i,j;
    52                 ak=0;
    53                 v=n;
    54                 for(i=0; i<=5; i++)
    55                 {
    56                          ak=0;dfs(2*n*n,i,1,false);
    57                          if(ak>=v)
    58                         {break;}
    59                 }
    60                 ak=0;
    61                 dfs(2*n*n,i,1,true);
    62                 printf("%I64d",ans[0]);
    63                 for(i=1; i<n; i++)
    64                         printf(" %I64d",ans[i]);
    65                 printf("
    ");
    66         }
    67         return 0;
    68 }
    油!油!you@
  • 相关阅读:
    myeclipse优化
    如何修改myeclipse的内存?eclipse.ini中各个参数的作用
    java日期处理
    拖放浮动效果——javascript
    4.什么时候加ing
    3.有些英语没有什么道理可讲的,不讲道理的习惯,必须要遵守
    数据库分页问题,跳页不正常问题解决办法
    谷歌地图计算两个坐标点的距离函数
    增加tomcat多实例 不忘初心
    ansible部署,规划 不忘初心
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5769006.html
Copyright © 2020-2023  润新知