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

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            色欲av伊人久久大香线蕉影院 | 97精品伊人久久大香线蕉app| 香蕉久久夜色精品国产2020 | 久久青青草原精品影院| 久久国产高清一区二区三区| 国产精品一区二区久久精品涩爱 | 精品久久久久久亚洲精品 | 99久久精品免费看国产| 久久影视综合亚洲| 久久精品国产99久久久| 国产福利电影一区二区三区久久久久成人精品综合 | 性欧美大战久久久久久久久| 久久精品免费一区二区三区| 久久综合久久性久99毛片| 色婷婷综合久久久久中文| 久久99久久成人免费播放| 粉嫩小泬无遮挡久久久久久| 97精品伊人久久大香线蕉| 久久精品无码一区二区三区免费| 亚洲国产精品无码久久久不卡 | 久久久亚洲裙底偷窥综合| 一本一道久久精品综合| 欧洲人妻丰满av无码久久不卡| 久久精品国产精品亚洲下载 | 国产精品亚洲综合专区片高清久久久| 久久久久亚洲AV成人网人人网站 | 99久久香蕉国产线看观香| 久久99国产精品成人欧美| 97久久天天综合色天天综合色hd| 一本色综合久久| 亚洲精品乱码久久久久久蜜桃| 国产精品久久久久乳精品爆| 久久精品国产福利国产秒| 久久精品人人做人人妻人人玩| 久久天天躁狠狠躁夜夜avapp | 亚洲国产精品无码久久| 久久久久久久久久久精品尤物 | www.久久热| 99久久www免费人成精品| 国产精品内射久久久久欢欢| 欧美精品一本久久男人的天堂|