• <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)論排行榜

            久久精品人成免费| 热re99久久精品国99热| 色综合久久中文综合网| 精品久久久久久久中文字幕| 欧美精品福利视频一区二区三区久久久精品 | 中文精品99久久国产| 久久久久久九九99精品| 精品久久久久久久| 久久国产劲爆AV内射—百度| 国产精品热久久无码av| 国产成人精品综合久久久| 久久精品国产一区二区三区不卡 | 久久国产香蕉视频| 中文无码久久精品| 国产毛片久久久久久国产毛片| 亚洲国产成人乱码精品女人久久久不卡 | 国产精品一区二区久久| 久久人妻少妇嫩草AV蜜桃| 国产精品久久久久9999| 久久久久久国产精品美女| 94久久国产乱子伦精品免费| 久久精品国产亚洲AV无码娇色| 久久精品国产亚洲Aⅴ香蕉 | 亚洲午夜久久久久妓女影院| 久久精品一区二区影院| 51久久夜色精品国产| 九九精品99久久久香蕉| 久久久久久午夜成人影院| 国产精品乱码久久久久久软件| 色8激情欧美成人久久综合电| 久久免费香蕉视频| 国产午夜久久影院| 精品久久8x国产免费观看| 五月丁香综合激情六月久久| 国产亚洲婷婷香蕉久久精品| 久久久久人妻一区二区三区| 中文精品久久久久人妻| 久久精品国产日本波多野结衣| 久久青青草原精品国产不卡| 久久精品综合一区二区三区| 久久久久亚洲AV成人网人人网站|