• <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 幻浪天空領主 閱讀(224) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久人人爽天天玩人人妻| 亚洲精品乱码久久久久久| 国产精品99久久精品| 欧美一区二区精品久久| 久久久噜噜噜久久| 久久国产色av免费看| 久久se精品一区二区| 久久影视国产亚洲| 漂亮人妻被黑人久久精品| 国产高清美女一级a毛片久久w| 亚洲国产二区三区久久| 久久精品国产免费| 无码精品久久久天天影视 | 久久久av波多野一区二区| 77777亚洲午夜久久多喷| 久久久久亚洲精品无码网址| 色综合久久中文字幕无码| 久久国产福利免费| 久久精品国产影库免费看| 狠狠色丁香久久婷婷综合_中 | 久久久亚洲欧洲日产国码aⅴ| 国产成人综合久久精品尤物| 伊人久久大香线蕉综合Av| 久久精品无码一区二区日韩AV | 亚洲国产一成人久久精品| 精品一久久香蕉国产线看播放| 精品久久久一二三区| 色偷偷偷久久伊人大杳蕉| 精品久久久久久久久久久久久久久| 亚洲欧美成人综合久久久| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 无码超乳爆乳中文字幕久久| 亚洲国产成人乱码精品女人久久久不卡 | 久久国产精品99国产精| 国产成人久久精品一区二区三区| 久久精品一区二区三区中文字幕| 久久精品国产一区二区三区日韩| 人人狠狠综合久久亚洲88| 久久最新精品国产| 国产激情久久久久影院| 伊人久久大香线焦综合四虎|