• <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)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久人人爽人人爽人人AV| 精品多毛少妇人妻AV免费久久 | 国产精品伊人久久伊人电影| 久久er国产精品免费观看2| 精品久久久久久久无码| 精品久久久久久无码中文字幕| 欧美亚洲国产精品久久高清| 久久精品国产亚洲AV无码偷窥 | 综合网日日天干夜夜久久| 亚洲AV无码久久精品色欲| 97精品久久天干天天天按摩| 久久99国产精品尤物| 久久夜色精品国产噜噜亚洲AV | 香蕉久久久久久狠狠色| 国产Av激情久久无码天堂| 中文字幕无码久久精品青草| 久久精品国产福利国产秒| 亚洲va中文字幕无码久久不卡| 国产激情久久久久影院老熟女| 久久天天躁狠狠躁夜夜躁2O2O| 日韩欧美亚洲综合久久影院Ds| 99久久无码一区人妻| www久久久天天com| 久久夜色精品国产噜噜噜亚洲AV| 久久久久亚洲AV成人网| 秋霞久久国产精品电影院| 99久久er这里只有精品18| 国产色综合久久无码有码| 伊人久久大香线蕉成人| 亚洲国产高清精品线久久| 人人狠狠综合久久亚洲| 久久久噜噜噜久久| 久久综合成人网| 久久国产免费直播| 无码精品久久一区二区三区| 理论片午午伦夜理片久久| 久久久黄片| 欧美日韩精品久久久久| 亚洲精品高清国产一线久久| 久久久久久久久无码精品亚洲日韩 | 中文字幕日本人妻久久久免费 |