zoukankan      html  css  js  c++  java
  • 3.1.3 Humble Numbers

    Humble Numbers

    For a given set of K prime numbers S = {p1, p2, ..., pK}, consider the set of all numbers whose prime factors are a subset of S. This set contains, for example, p1, p1p2, p1p1, and p1p2p3 (among others). This is the set of `humble numbers' for the input set S. Note: The number 1 is explicitly declared not to be a humble number.

    Your job is to find the Nth humble number for a given set S. Long integers (signed 32-bit) will be adequate for all solutions.

    PROGRAM NAME: humble

    INPUT FORMAT

    Line 1: Two space separated integers: K and N, 1 <= K <=100 and 1 <= N <= 100,000.
    Line 2: K space separated positive integers that comprise the set S.

    SAMPLE INPUT (file humble.in)

    4 19
    2 3 5 7
    

    OUTPUT FORMAT

    The Nth humble number from set S printed alone on a line.

    SAMPLE OUTPUT (file humble.out)

    27

    /*
    ID: makeeca1
    PROG: humble
    LANG: C++
    */
    #include <cstdio>
    #include<climits>
    using namespace std;
    #define MAX 200
    int k,n,a[MAX],ans[100001],dex[MAX],count,min;
    int main(){
        freopen("humble.in","r",stdin);
        freopen("humble.out","w",stdout);
        scanf("%d%d",&k,&n);
        for (int i=0;i<k;i++) scanf("%d",&a[i]);
        count=1;
        ans[0]=1;
        while (count<n+1){
            min=INT_MAX;
            for (int i=0;i<k;i++){
                while ((long long)a[i]*ans[dex[i]]<=ans[count-1])dex[i]++;
                if ((long long )a[i]*ans[dex[i]]<min)min=a[i]*ans[dex[i]];
            }
            ans[count++]=min;
        }
        printf("%d
    ",ans[n]);
        return 0;
    }
  • 相关阅读:
    【2020省选模拟】01.18比赛总结
    【2020省选模拟】01.17比赛总结
    利用dockerfile 安装一个tomcat7
    docker的基本安装和命令详解
    jumpserver1.4.1 安装过程
    Redis info参数总结
    ansible-service
    ansible-yum
    centos源码安装mariadb和Galera 多主集群
    ansible常用模块
  • 原文地址:https://www.cnblogs.com/makeecat/p/3289222.html
Copyright © 2011-2022 走看看