• <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)主 閱讀(368) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲第一永久AV网站久久精品男人的天堂AV| 久久久国产打桩机| 蜜臀av性久久久久蜜臀aⅴ| 亚洲精品美女久久久久99| 久久国产精品77777| 亚洲国产天堂久久综合网站 | 热99re久久国超精品首页| 久久精品国产精品青草 | 精品久久久久久久久免费影院| 无码任你躁久久久久久老妇| 久久青青色综合| 国产情侣久久久久aⅴ免费| 久久婷婷色香五月综合激情| 国产日产久久高清欧美一区| 亚洲AV无码久久精品狠狠爱浪潮| 久久久久久亚洲精品影院| 久久99国内精品自在现线| 久久亚洲欧洲国产综合| 久久ww精品w免费人成| 久久精品国产黑森林| 久久综合狠狠综合久久| 手机看片久久高清国产日韩 | 久久精品国产亚洲AV无码偷窥| 91精品国产91久久| 亚洲va中文字幕无码久久 | 国产亚洲欧美成人久久片| 久久婷婷午色综合夜啪| 99久久99久久精品国产片果冻| 无码人妻少妇久久中文字幕蜜桃 | 99久久免费国产精品| 国产成人无码久久久精品一| 热99RE久久精品这里都是精品免费 | 伊人久久无码中文字幕| 一本色道久久88综合日韩精品| 欧美久久精品一级c片片| 久久人人爽人人爽人人AV东京热| 中文字幕精品无码久久久久久3D日动漫 | 无码精品久久一区二区三区 | 国产精品99久久精品| 狠狠色丁香婷综合久久| 久久国产成人精品麻豆|