• <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)主 閱讀(217) 評(píng)論(0)  編輯 收藏 引用 所屬分類: USACO

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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            伊人久久无码中文字幕| 精品久久人人做人人爽综合| 久久精品极品盛宴观看| 天天爽天天狠久久久综合麻豆| 99久久人妻无码精品系列蜜桃| 国产成人精品久久亚洲高清不卡| 亚洲精品无码久久久| 丰满少妇人妻久久久久久| 亚洲精品成人网久久久久久| 国产亚洲欧美成人久久片 | 伊人色综合久久天天人守人婷| 久久99精品国产麻豆| 亚洲伊人久久综合影院| 久久综合欧美成人| 国产美女久久精品香蕉69| 久久久久久精品无码人妻| 国产一区二区精品久久岳| 久久99精品国产自在现线小黄鸭 | 久久伊人影视| 久久伊人精品青青草原高清| 人妻精品久久久久中文字幕一冢本| 九九热久久免费视频| 亚洲国产精品一区二区久久| 久久亚洲欧美国产精品| 色偷偷88888欧美精品久久久| 午夜精品久久久久久影视777| 草草久久久无码国产专区| 久久91精品国产91久久户| 久久久久99精品成人片欧美| 国产成人无码精品久久久性色| 亚洲а∨天堂久久精品| 亚洲国产精品综合久久一线| 国产成人精品久久一区二区三区av | 国产成人精品久久免费动漫 | 久久久久久狠狠丁香| 久久精品国产亚洲AV大全| 亚洲va久久久噜噜噜久久男同| 无码人妻久久一区二区三区 | 日本人妻丰满熟妇久久久久久| 亚洲精品乱码久久久久久 | 欧美精品丝袜久久久中文字幕 |