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

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            a级毛片无码兔费真人久久| 久久久久一区二区三区| 思思久久99热只有频精品66| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 国产伊人久久| 久久亚洲中文字幕精品一区| 久久国产劲爆AV内射—百度| 精品久久久久久久无码| 91久久精品91久久性色| 久久久久亚洲精品无码网址| 久久综合给合久久狠狠狠97色 | 成人久久综合网| 亚洲国产综合久久天堂 | 伊人久久综合无码成人网| 国产精品久久99| 久久精品国产亚洲AV忘忧草18| 久久精品国产亚洲AV大全| 嫩草影院久久国产精品| yy6080久久| 久久久国产精品| 国产精品无码久久综合网| 久久精品国产亚洲av水果派| 久久这里只精品99re66| 久久婷婷色综合一区二区| 久久婷婷久久一区二区三区| 亚洲va久久久噜噜噜久久男同| 久久久免费观成人影院 | 亚洲AV日韩精品久久久久久| 精品久久久久久无码免费| 国产成人精品免费久久久久| 久久婷婷五月综合成人D啪| 精品久久综合1区2区3区激情| 99久久无码一区人妻| 99久久久国产精品免费无卡顿 | 伊人久久大香线蕉影院95| 新狼窝色AV性久久久久久| 中文字幕久久波多野结衣av| 色老头网站久久网| 亚洲午夜久久久久久久久久| 久久亚洲AV无码精品色午夜 | 国产精品永久久久久久久久久 |