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

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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久成人精品视频| 成人免费网站久久久| 伊人久久免费视频| 色妞色综合久久夜夜| 无码人妻少妇久久中文字幕蜜桃| 久久天天躁狠狠躁夜夜不卡| 亚洲香蕉网久久综合影视| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久香综合精品久久伊人| 久久亚洲国产成人影院| 麻豆精品久久久久久久99蜜桃 | 久久99久久99精品免视看动漫| 久久人人爽人人爽人人av东京热| 天天躁日日躁狠狠久久| 久久国产精品久久| 亚洲精品综合久久| 午夜久久久久久禁播电影| 国内精品久久久久影院一蜜桃| 久久99国产精品一区二区| 久久无码精品一区二区三区| 成人综合久久精品色婷婷| 久久er99热精品一区二区| 蜜桃麻豆www久久国产精品| 狠狠色婷婷久久一区二区| 久久青草国产精品一区| 亚洲欧美国产精品专区久久| 久久人人爽人人爽人人AV| 亚洲嫩草影院久久精品| 亚洲精品乱码久久久久久蜜桃| 日韩精品无码久久久久久| 国产精品嫩草影院久久| 亚洲国产欧美国产综合久久| 国产成人精品久久亚洲高清不卡| 久久婷婷色香五月综合激情| 久久精品国产99国产精偷| 一本色综合网久久| 人妻丰满?V无码久久不卡| 久久精品这里热有精品| 无码精品久久久久久人妻中字| 亚洲国产成人精品女人久久久 | 国产亚洲欧美成人久久片|