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

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久国产打桩机| 品成人欧美大片久久国产欧美...| 精品久久久久中文字幕一区| 久久国产热这里只有精品| 久久综合狠狠综合久久97色| 久久精品一区二区三区AV| 久久久久久亚洲精品成人| 国产福利电影一区二区三区久久老子无码午夜伦不 | 69国产成人综合久久精品| 99久久精品免费| 亚洲综合精品香蕉久久网| 91精品国产综合久久香蕉| 久久精品中文字幕一区 | 青青青国产精品国产精品久久久久| 久久艹国产| 国产精品免费福利久久| 怡红院日本一道日本久久| 日本精品一区二区久久久| 欧美日韩中文字幕久久伊人| 国产亚洲美女精品久久久2020| 久久精品国产亚洲Aⅴ香蕉| 国内精品久久久久影院日本| 亚洲精品美女久久久久99小说| 久久久久久久综合日本亚洲| 婷婷五月深深久久精品| 久久精品国产日本波多野结衣| 狠狠色伊人久久精品综合网 | 亚洲国产小视频精品久久久三级| 久久久噜噜噜久久中文福利| 狠狠色丁香婷婷久久综合五月| 亚洲综合精品香蕉久久网97| 久久精品亚洲一区二区三区浴池 | 久久久一本精品99久久精品88| 久久精品国产第一区二区| 国产精品视频久久久| 国产一级持黄大片99久久| 久久久久久亚洲AV无码专区| 国产V亚洲V天堂无码久久久| 奇米综合四色77777久久| 久久国产色AV免费看| 国产成人精品免费久久久久|