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


            這題主要是去掉階乘末尾的0。是個(gè)老題了,編程之美中就有討論。因?yàn)?都是由2*5得來的。只要找出乘數(shù)中有多少個(gè)2*5對(duì)就行了。
            因?yàn)?的個(gè)數(shù)遠(yuǎn)多于5,所以只要找出5的個(gè)數(shù)即可。因?yàn)閚最大為4220,5的個(gè)數(shù)為:
            n/5+n/5/5+n/5/5/5+n/5/5/5/5+n/5/5/5/5/5+n/5/5/5/5/5/5;
            然后再去除相應(yīng)數(shù)目的2。這樣剩下的數(shù)只需兩兩相乘后取最后一位即可。

            #include?<iostream>
            #include?
            <fstream>

            using?namespace?std;

            ifstream in(
            "fact4.in");
            ofstream out(
            "fact4.out");

            void?solve()
            {
            ????
            int?n;
            ????
            in>>n;

            ????
            int?numof5?=?n/5+n/5/5+n/5/5/5+n/5/5/5/5+n/5/5/5/5/5+n/5/5/5/5/5/5;

            ????
            int?res?=?1;

            ????
            int?tmp;

            ????
            for(int?i=1;i<=n;++i){
            ????????tmp?
            =?i;
            ????????
            while(tmp%5==0)?tmp/=5;
            ????????
            while(tmp%2==0&&numof5!=0){
            ????????????tmp
            /=2;
            ????????????numof5
            --;
            ????????}
            ????????res
            *=tmp;
            ????????res
            %=10;
            ????}

            ????
            out<<res<<endl;
            }

            int?main(int?argc,char?*argv[])
            {
            ????solve();?
            ????
            return?0;
            }


            原題:
            Factorials

            The factorial of an integer N, written N!, is the product of all the integers from 1 through N inclusive. The factorial quickly becomes very large: 13! is too large to store in a 32-bit integer on most computers, and 70! is too large for most floating-point variables. Your task is to find the rightmost non-zero digit of n!. For example, 5! = 1 * 2 * 3 * 4 * 5 = 120, so the rightmost non-zero digit of 5! is 2. Likewise, 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040, so the rightmost non-zero digit of 7! is 4.

            PROGRAM NAME: fact4

            INPUT FORMAT

            A single positive integer N no larger than 4,220.

            SAMPLE INPUT (file fact4.in)

            7

            OUTPUT FORMAT

            A single line containing but a single digit: the right most non-zero digit of N! .

            SAMPLE OUTPUT (file fact4.out)

            4

            posted on 2009-07-03 19:52 YZY 閱讀(242) 評(píng)論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO

            導(dǎo)航

            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            2019久久久高清456| 久久九九全国免费| 久久精品一本到99热免费| 少妇久久久久久久久久| 情人伊人久久综合亚洲| 久久热这里只有精品在线观看| 久久精品国产亚洲av高清漫画| 久久精品国产WWW456C0M| 99久久国产精品免费一区二区| 日本精品久久久中文字幕| 无码八A片人妻少妇久久| 亚洲午夜久久影院| 72种姿势欧美久久久久大黄蕉| 一本大道久久东京热无码AV| 伊人久久大香线蕉影院95| 婷婷伊人久久大香线蕉AV | 97超级碰碰碰久久久久| 四虎影视久久久免费观看| 久久综合综合久久狠狠狠97色88| 伊人情人综合成人久久网小说| 伊人丁香狠狠色综合久久| 国产精品久久国产精麻豆99网站| 亚洲狠狠婷婷综合久久久久| 色偷偷88欧美精品久久久 | 日韩AV毛片精品久久久| 91精品无码久久久久久五月天| 久久久久人妻一区精品性色av| 亚洲中文字幕伊人久久无码| 蜜臀久久99精品久久久久久| 精品久久久久久久中文字幕| 99久久精品国内| 成人免费网站久久久| 国产精品一久久香蕉产线看 | 久久精品毛片免费观看| 亚洲精品国产字幕久久不卡| 亚洲人成伊人成综合网久久久| 亚洲国产视频久久| 亚洲国产精品久久久天堂| 久久久久亚洲AV成人片 | 三级三级久久三级久久| 久久久久久精品免费看SSS|