• <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>

            xLsDg

            Xiao Lu Software Development Group
            posts - 8, comments - 1, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            尋找第1500個丑數

            Posted on 2014-07-19 12:20 xLsDg 閱讀(341) 評論(0)  編輯 收藏 引用 所屬分類: 代碼庫
             1 #include <stdio.h>
             2 #include <stdlib.h>
             3 
             4 unsigned long getUglyNumber( unsigned long index )
             5 {
             6     unsigned long *pMax = NULL, *pMax2 = NULL, *pMax3 = NULL, *pMax5 = NULL, *pUgly = NULL;
             7     unsigned long min = 0, max = 0, max2 = 0, max3 = 0, max5 = 0;
             8 
             9     if( 1 > index ) {
            10         return ( unsigned long )0;
            11     }
            12 
            13     pUgly = ( unsigned long* )malloc( ( size_t )index * sizeof( unsigned long ) );
            14     if ( NULL == pUgly ) {
            15         return ( unsigned long )0;
            16     }
            17 
            18     pMax = pMax2 = pMax3 = pMax5 = pUgly;
            19     *pUgly = 1;
            20 
            21     while ( pMax - pUgly < index - 1 ) {
            22         max2 = *pMax2 * 2;
            23         max3 = *pMax3 * 3;
            24         max5 = *pMax5 * 5;
            25 
            26         min = ( max2 < max3 ) ? max2 : max3;
            27 
            28         *( ++pMax ) = ( min < max5 ) ? min : max5;
            29 
            30         while ( *pMax2 * 2 <= *pMax ) ++pMax2;
            31         while ( *pMax3 * 3 <= *pMax ) ++pMax3;
            32         while ( *pMax5 * 5 <= *pMax ) ++pMax5;
            33     }
            34 
            35     max = *pMax;
            36 
            37     free( pUgly );
            38 
            39     return max;
            40 }
            41 
            42 int main()
            43 {
            44     unsigned long index = 1500;
            45     printf( "The No.%u ugly number is %u." , index, getUglyNumber( index ) );
            46     return 0;
            47 }
            48 
            国内精品久久久久久中文字幕| 久久强奷乱码老熟女网站| 亚洲午夜久久久久久噜噜噜| 亚洲av日韩精品久久久久久a | 99久久www免费人成精品| 7国产欧美日韩综合天堂中文久久久久| 国内精品久久久久久久久| 亚洲日本va午夜中文字幕久久| 国内精品久久久久伊人av| 日日狠狠久久偷偷色综合96蜜桃| 久久婷婷五月综合97色一本一本| 久久久久久亚洲精品无码| 九九精品99久久久香蕉| 久久涩综合| 日本精品久久久中文字幕 | 久久久国产打桩机| 精品久久久久中文字幕一区| 无码专区久久综合久中文字幕| 久久精品中文字幕有码| 欧美激情精品久久久久| 久久久久国产精品嫩草影院| 久久影院午夜理论片无码| 国产精品久久久久久影院 | 久久国产免费直播| 久久精品无码一区二区三区免费| 国产精品国色综合久久| 久久久久av无码免费网| 一级做a爰片久久毛片毛片| 亚洲精品高清国产一久久| 久久夜色tv网站| 久久精品国产亚洲麻豆| 久久精品这里热有精品| 久久精品成人国产午夜| 久久精品国产69国产精品亚洲| 久久精品国产亚洲AV香蕉| 精品久久久久久无码中文字幕一区 | 亚洲精品无码久久不卡| 日本精品一区二区久久久| 亚洲精品无码久久不卡| 国产精品久久久久免费a∨| 区久久AAA片69亚洲|