• <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 幻浪天空領(lǐng)主 閱讀(371) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            无码超乳爆乳中文字幕久久| 人妻无码αv中文字幕久久琪琪布| 国产成人AV综合久久| 国产精品日韩欧美久久综合| 久久99精品久久久久久噜噜| 狠狠综合久久综合88亚洲| 国产精品久久久久久久久| 伊人久久大香线蕉综合热线| 久久超碰97人人做人人爱| 久久久久综合国产欧美一区二区| 亚洲精品无码久久久久去q | 亚洲欧洲中文日韩久久AV乱码| 亚洲∧v久久久无码精品| 国产高清国内精品福利99久久| 久久亚洲私人国产精品| 麻豆国内精品久久久久久| 久久亚洲国产精品一区二区| 人人妻久久人人澡人人爽人人精品 | 久久久久亚洲av无码专区导航| 伊人久久大香线蕉综合网站| 97超级碰碰碰碰久久久久| 色偷偷88888欧美精品久久久| 日韩久久久久中文字幕人妻 | 国产亚洲精品自在久久| 一本久久a久久精品亚洲| 久久影院久久香蕉国产线看观看| 国产精品一区二区久久| 国产精品久久久亚洲| 久久99国内精品自在现线| 狠狠色婷婷久久综合频道日韩| 色婷婷久久久SWAG精品| 久久综合精品国产一区二区三区| 91超碰碰碰碰久久久久久综合| 久久亚洲国产午夜精品理论片| 91精品国产乱码久久久久久| 国产精品无码久久久久久| 色欲综合久久躁天天躁蜜桃| 狠狠综合久久AV一区二区三区| 色偷偷偷久久伊人大杳蕉| 99久久国语露脸精品国产| 伊人色综合久久|