• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            USACO Section 3.1 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
            Analysis

            At the first glance of it, I missunderstood it as a DP problem. But later, I realized that we can simply make an array to store all of the "humble numbers", which is constructed in a way to add the minimum number among all the numbers just larger than the last one.
            To archive it within little time, I use an array recording the power of the given prime number, for instance, the power of p[i] is called pri[i], and increasing the pri[i] to find the minimum number.

            Code

             

            /*
            ID:braytay1
            PROG:humble
            LANG:C++
            */

            #include 
            <iostream>
            #include 
            <fstream>
            using namespace std;

            int main(){
                ifstream fin(
            "humble.in");
                ofstream fout(
            "humble.out");
                
            int k,n;
                
            int p[100],pri[100];
                
            long long int humble[100001];
                fin
            >>k>>n;
                
            for (int i=0;i<k;i++) fin>>p[i];
                memset(pri,
            0,sizeof(pri));
                memset(humble,
            0,sizeof(humble));
                humble[
            0]=1;
                
            int max=-1;
                
            for (int i=0;i<k;i++){
                    
            if (max<p[i]) max=p[i];
                }
                
                
            for (int i=1;i<=n;i++){
                    
            long long int min;
                    min
            =humble[i-1]*p[0]*p[0];
                    
            for (int k1=0;k1<k;k1++){
                        
            while(humble[pri[k1]]*p[k1]<=humble[i-1]) pri[k1]++;
                        
            if (humble[pri[k1]]*p[k1]<min) min=humble[pri[k1]]*p[k1];
                    }

                    humble[i]
            =min;
                }

                fout
            <<humble[n]<<endl;
                
            return 0;
            }


             

            posted on 2008-08-20 23:11 幻浪天空領主 閱讀(367) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            日韩久久久久中文字幕人妻 | 伊人色综合久久| 国产精品久久久久影院嫩草| 色欲综合久久中文字幕网| 国内精品久久久久| 蜜臀久久99精品久久久久久| 中文字幕久久精品无码| 国产精品9999久久久久| 热综合一本伊人久久精品| 久久WWW免费人成一看片| 国产成人99久久亚洲综合精品| 中文字幕无码久久人妻| 国产亚洲精久久久久久无码| 热久久国产欧美一区二区精品| 久久久久亚洲精品天堂| 色99久久久久高潮综合影院| 热re99久久精品国产99热| 久久久国产精华液| 久久有码中文字幕| 国产91色综合久久免费| 久久久久久久综合狠狠综合| 狠狠色丁香久久综合五月| 99精品久久精品一区二区| 久久精品国产精品亜洲毛片| 久久美女网站免费| 久久久久久亚洲AV无码专区| 国产aⅴ激情无码久久| 日韩电影久久久被窝网| 久久亚洲国产精品123区| 亚洲成人精品久久| 久久这里只精品国产99热| 久久精品夜夜夜夜夜久久| 亚洲精品乱码久久久久66| 伊人久久无码中文字幕| 久久精品国产免费观看| 久久无码AV中文出轨人妻| 色99久久久久高潮综合影院| 国产精品99久久久精品无码| 狠狠色丁香久久婷婷综合| 色婷婷久久综合中文久久蜜桃av| 亚洲精品午夜国产VA久久成人|