• <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。是個老題了,編程之美中就有討論。因為0都是由2*5得來的。只要找出乘數中有多少個2*5對就行了。
            因為2的個數遠多于5,所以只要找出5的個數即可。因為n最大為4220,5的個數為:
            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;
            然后再去除相應數目的2。這樣剩下的數只需兩兩相乘后取最后一位即可。

            #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 閱讀(240) 評論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO

            導航

            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            統計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久国产午夜精品一区二区三区| 亚洲午夜久久久影院伊人| AA级片免费看视频久久| 久久丝袜精品中文字幕| 91精品国产乱码久久久久久| 久久国产香蕉视频| 99久久人妻无码精品系列蜜桃| 久久国产香蕉视频| 久久久久99精品成人片试看| 亚洲成av人片不卡无码久久| 久久99国产精一区二区三区| 77777亚洲午夜久久多喷| 99热成人精品免费久久| 色婷婷综合久久久久中文| 久久久久久久国产免费看| 国产成年无码久久久久毛片| 久久九九兔免费精品6| 青青草原综合久久大伊人导航| 精品久久久久香蕉网| 久久无码专区国产精品发布| 久久国产乱子伦精品免费午夜| 99久久免费国产精精品| 伊人久久大香线蕉综合Av| 亚洲伊人久久综合中文成人网| 欧美久久久久久精选9999| 亚洲成色999久久网站| 韩国三级大全久久网站| 国产成人精品久久免费动漫| 久久精品国产亚洲AV麻豆网站 | 精品国产一区二区三区久久| 人妻少妇久久中文字幕一区二区| 无码人妻久久一区二区三区蜜桃 | 欧美久久一区二区三区| 国产91久久综合| 久久精品国产99久久丝袜| 韩国三级中文字幕hd久久精品| 亚洲成人精品久久| 99国内精品久久久久久久| 狠狠精品久久久无码中文字幕 | 少妇久久久久久被弄高潮| 久久久老熟女一区二区三区|