• <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得來的。只要找出乘數(shù)中有多少個2*5對就行了。
            因為2的個數(shù)遠(yuǎn)多于5,所以只要找出5的個數(shù)即可。因為n最大為4220,5的個數(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) 評論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO

            導(dǎo)航

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

            統(tǒng)計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            a级成人毛片久久| 国产欧美一区二区久久| 热综合一本伊人久久精品 | 爱做久久久久久| 久久www免费人成精品香蕉| 亚洲国产成人久久精品99| 人妻久久久一区二区三区| 国产免费久久精品丫丫| 东方aⅴ免费观看久久av| 国产精品禁18久久久夂久| 日日狠狠久久偷偷色综合免费| 亚洲精品乱码久久久久久按摩| 97精品国产97久久久久久免费| 欧美日韩久久中文字幕| 99久久亚洲综合精品成人| 亚洲国产精品高清久久久| 久久久久成人精品无码| 91精品国产高清91久久久久久| 中文成人无码精品久久久不卡 | 久久国产精品-久久精品| 国内精品伊人久久久久妇| 国产AV影片久久久久久 | 欧美一级久久久久久久大片 | 无码任你躁久久久久久| 高清免费久久午夜精品| 亚洲AV日韩AV天堂久久| 久久这里只精品99re66| 99久久夜色精品国产网站| 伊人久久免费视频| 亚洲国产成人久久综合一| 狠狠狠色丁香婷婷综合久久俺| 色欲久久久天天天综合网| 久久99热这里只有精品国产| 亚洲va久久久久| 精品久久久久久无码不卡| 久久亚洲精品无码VA大香大香| 久久婷婷色综合一区二区| 欧美麻豆久久久久久中文| 国产精品久久久久蜜芽| 中文字幕久久波多野结衣av| 久久伊人五月丁香狠狠色|