• <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久久丝袜| 婷婷综合久久中文字幕| 午夜精品久久久久9999高清| 国产精品成人久久久| 99久久国产宗和精品1上映| 久久久精品2019免费观看| 91精品国产色综久久| 国产69精品久久久久久人妻精品| 国内精品久久久久久野外| 国产精品久久久香蕉| 免费观看久久精彩视频| 亚洲中文字幕无码久久2020| 国产成人久久精品麻豆一区| 狠狠色丁香久久婷婷综合蜜芽五月| 久久久久亚洲AV成人片| 久久无码人妻精品一区二区三区| 精品久久久久久无码中文字幕一区| 久久99久久无码毛片一区二区| 久久大香香蕉国产| 中文字幕久久亚洲一区| 久久91精品综合国产首页| 91精品日韩人妻无码久久不卡| 亚洲国产精品无码久久98| 日本五月天婷久久网站| 亚洲国产精品无码久久青草| 久久99久久成人免费播放| 91精品国产91久久久久久青草| 777米奇久久最新地址| 亚洲级αV无码毛片久久精品 | 人人狠狠综合久久亚洲88| 亚洲国产精品18久久久久久| 亚洲七七久久精品中文国产| 久久夜色撩人精品国产| 久久久久久久久久免免费精品 | 久久乐国产综合亚洲精品| 久久精品无码av| 久久久久亚洲爆乳少妇无| 一本久久综合亚洲鲁鲁五月天| 久久久精品人妻无码专区不卡|