• <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| 国产成人精品久久| 免费无码国产欧美久久18| 久久精品中文无码资源站| 久久w5ww成w人免费| 久久亚洲天堂| 色综合久久综精品| 香蕉久久夜色精品国产2020| 久久精品国产清高在天天线| 久久亚洲国产成人影院网站| 欧美大香线蕉线伊人久久| 久久婷婷五月综合色99啪ak| 精品综合久久久久久888蜜芽| 日产久久强奸免费的看| 久久精品a亚洲国产v高清不卡| 久久亚洲国产精品123区| 久久er热视频在这里精品| 午夜精品久久久久9999高清| 大香网伊人久久综合网2020| 婷婷综合久久中文字幕蜜桃三电影| 欧美色综合久久久久久 | 亚洲人成无码www久久久| av无码久久久久不卡免费网站| 中文字幕无码久久人妻| 国内精品久久久久久不卡影院| 99久久超碰中文字幕伊人| 欧美日韩精品久久免费| 亚洲婷婷国产精品电影人久久| 精品久久人人妻人人做精品| 久久99精品国产一区二区三区 | 久久精品国产欧美日韩99热| 色综合久久最新中文字幕| 国产精品99久久久久久人| 国内精品久久久久久99蜜桃 | 国产精品女同一区二区久久| 99久久这里只有精品| 潮喷大喷水系列无码久久精品 | 久久久久九九精品影院| 久久se这里只有精品| 欧美国产成人久久精品| 亚洲精品97久久中文字幕无码|