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

            Counting fractions

            TimeLimit: 2000MS  MemoryLimit: 65536 Kb

            Totalsubmit: 39   Accepted: 6  

            Description

            Consider the fraction, n/d, where n and d are positive integers. If <= d and HCF(n,d)=1, it is called a reduced proper fraction.

            If we list the set of reduced proper fractions for d <= 8 in ascending order of size, we get:

            1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8

            It can be seen that there are 21 elements in this set.

            How many elements would be contained in the set of reduced proper fractions for d <= x?

            Input

            The input will consist of a series of x, 1 < x < 1000001.

            Output

            For each input integer x, you should output the number of elements contained in the set of reduced proper fractions for d <= x in one line.

            Sample Input

            3

            8

            Sample Output

            3
            21

            Hint

            HCF代表最大公約數(shù)

            這里主要說一下素?cái)?shù)篩法,該方法可以快速的選取出1~N數(shù)字中的所有素?cái)?shù)。時(shí)間復(fù)雜度遠(yuǎn)小于O(N*sqrt(N))
            方法為:從2開始,往后所有素?cái)?shù)的倍數(shù)都不是素?cái)?shù)。最后剩下的數(shù)都是素?cái)?shù)。
            再說說歐拉公式,用來解決所有小于n中的數(shù)字有多少個(gè)與n互質(zhì),用Ψ(n)表示。
            Ψ(n)=n*(1-1/q1)*(1-1/q2)*……*(1-1/qk),n為和數(shù),其中qi為n的質(zhì)因數(shù)。
            Ψ(n)=n-1,n為質(zhì)數(shù)
            注意:關(guān)于數(shù)論的題很容易超過int類型的范圍,多考慮用long long類型。
            歐拉函數(shù)請(qǐng)參閱:http://zh.wikipedia.org/zh-cn/%E6%AC%A7%E6%8B%89%E5%87%BD%E6%95%B0

            代碼

             

            posted on 2013-04-30 21:26 小鼠標(biāo) 閱讀(1292) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 數(shù)論

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2013年4月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            常用鏈接

            隨筆分類(111)

            隨筆檔案(127)

            friends

            最新評(píng)論

            閱讀排行榜

            成人综合久久精品色婷婷| 漂亮人妻被黑人久久精品| 精品久久久无码人妻中文字幕豆芽 | 国产成人精品三上悠亚久久| 伊人久久大香线蕉综合Av| 777午夜精品久久av蜜臀| 久久香综合精品久久伊人| 国产精品久久久久久久久软件| 99久久免费只有精品国产| 亚洲国产精品久久| 国内精品久久久久久中文字幕| 青青青青久久精品国产h| 久久93精品国产91久久综合| 青春久久| 五月丁香综合激情六月久久| 久久久久久久97| 国产呻吟久久久久久久92| 久久九九久精品国产免费直播| 亚洲国产成人精品无码久久久久久综合 | 久久久久久久久久久久中文字幕 | 久久久久国色AV免费看图片| 国产真实乱对白精彩久久| 久久一本综合| 亚洲欧美日韩中文久久| 久久99精品国产麻豆宅宅| 精品久久久久久无码中文字幕 | 99久久综合国产精品免费| 狠狠色丁香久久婷婷综合| 久久99亚洲网美利坚合众国| 中文字幕成人精品久久不卡| 国产午夜精品久久久久九九| 亚洲美日韩Av中文字幕无码久久久妻妇 | 国产69精品久久久久777| 草草久久久无码国产专区| 欧美日韩精品久久免费| 99国产精品久久| 国产69精品久久久久APP下载| 99久久99久久| 偷窥少妇久久久久久久久| 国产亚洲婷婷香蕉久久精品| 亚洲?V乱码久久精品蜜桃|