• <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得來(lái)的。只要找出乘數(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 閱讀(233) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): AlgorithmUSACO

            導(dǎo)航

            <2013年5月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類(lèi)

            隨筆檔案

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            色综合久久久久久久久五月| 久久精品亚洲欧美日韩久久| 亚洲人成无码久久电影网站| 精品久久人人做人人爽综合| 久久93精品国产91久久综合| 91精品国产综合久久四虎久久无码一级 | 久久精品桃花综合| 午夜精品久久久内射近拍高清| 久久久这里有精品中文字幕| 久久无码人妻精品一区二区三区| 久久精品国产一区二区电影| 久久青青国产| 大香伊人久久精品一区二区| 少妇高潮惨叫久久久久久| 无码人妻久久一区二区三区免费| 久久99亚洲网美利坚合众国| 精品亚洲综合久久中文字幕| 国产成人久久久精品二区三区 | 亚洲中文字幕无码久久综合网| 一本久久精品一区二区| 囯产精品久久久久久久久蜜桃| 亚洲AV日韩精品久久久久久| AV无码久久久久不卡网站下载 | 婷婷久久综合九色综合98| 国产精品美女久久久免费| 午夜精品久久久久久影视777| 亚洲精品无码久久久久| 一级做a爰片久久毛片16| 色诱久久av| 国内精品伊人久久久久| 久久人搡人人玩人妻精品首页| 亚洲成色WWW久久网站| 999久久久国产精品| 久久无码高潮喷水| 国产午夜精品久久久久九九电影 | 理论片午午伦夜理片久久 | 国产午夜久久影院| 伊人久久大香线蕉成人| 青青草国产精品久久久久| 久久久这里有精品| 国产精品美女久久久网AV|