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

            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
            Analysis

            Considering the small amount of 4,220, we can find that the highest number of zeros is 5 since 5^5<4,220<5^6. What we are interested in is the last 6 numbers after each step of factorial. At last, we may output the last non-zero digit.

            Code
            /*
            ID:braytay1
            PROG:fact4
            LANG:C++
            */

            #include 
            <iostream>
            #include 
            <fstream>
            using namespace std;

            int main(){
                ifstream fin(
            "fact4.in");
                ofstream fout(
            "fact4.out");
                
            int n;
                
            int s;
                fin
            >>n;
                s
            =1;
                
            for (int i=1;i<=n;i++){
                    s
            *=i;
                    
            if (s>=100000&&s%10==0{
                        
            while (s%10==0)    
                            s
            /=10;
                        s
            %=100000;
                    }

                    
            else s%=100000;
                }

                
            while (s%10==0)    
                    s
            /=10;
                fout
            <<s%10<<endl;
                
            return 0;
            }


            posted on 2008-08-22 20:36 幻浪天空領(lǐng)主 閱讀(219) 評(píng)論(0)  編輯 收藏 引用 所屬分類: USACO

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久夜色精品国产亚洲av| 亚洲а∨天堂久久精品| 国产69精品久久久久9999| 久久精品二区| 久久久久99精品成人片试看| 99久久99久久精品国产| 一本久道久久综合狠狠爱| 久久99精品久久久久久噜噜| 少妇内射兰兰久久| 日本欧美国产精品第一页久久| 丁香五月网久久综合| 久久精品国产久精国产一老狼| 亚洲国产成人久久综合一| 久久亚洲国产成人精品性色| 无码人妻久久一区二区三区蜜桃| 国产精品久久久久天天影视| 久久久久亚洲av综合波多野结衣| 狠狠色伊人久久精品综合网| AV无码久久久久不卡网站下载 | 爱做久久久久久| 欧洲成人午夜精品无码区久久| 亚洲国产成人精品女人久久久 | 久久人人添人人爽添人人片牛牛| 9999国产精品欧美久久久久久 | 2019久久久高清456| 久久人人爽人人爽人人片AV麻豆 | 色诱久久久久综合网ywww | 欧美精品一区二区久久| 国产成人精品久久综合 | 中文无码久久精品| 亚洲综合精品香蕉久久网| 亚洲国产精品无码久久九九| 久久久久九九精品影院| 精品免费久久久久国产一区| 伊人久久大香线蕉影院95| 77777亚洲午夜久久多喷| 久久九九亚洲精品| 久久精品一区二区| 色综合久久综合网观看| 亚洲狠狠久久综合一区77777| 97精品伊人久久久大香线蕉|