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

            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆檔案(2)

            文章分類(23)

            文章檔案(22)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            中文字幕无码精品亚洲资源网久久 | 国产成人久久AV免费| 久久国产高潮流白浆免费观看| 青青草原综合久久| 午夜精品久久久久久影视riav | 欧美久久精品一级c片片| 亚洲国产精品成人久久蜜臀| 欧美大香线蕉线伊人久久| 丁香久久婷婷国产午夜视频| 亚洲午夜久久久影院| 欧美与黑人午夜性猛交久久久| 久久99国产综合精品| 久久人人添人人爽添人人片牛牛| 国产精品无码久久四虎| 91久久精一区二区三区大全| 77777亚洲午夜久久多人| 亚洲美日韩Av中文字幕无码久久久妻妇 | 无码伊人66久久大杳蕉网站谷歌| 久久99久久无码毛片一区二区| 人妻精品久久无码专区精东影业| 午夜视频久久久久一区| 国产精品日韩深夜福利久久| 国产婷婷成人久久Av免费高清 | 91亚洲国产成人久久精品| AV无码久久久久不卡网站下载| 亚洲AV无码久久精品成人| 日韩精品久久久久久久电影| 青青青青久久精品国产h久久精品五福影院1421 | 久久99这里只有精品国产| 久久九九久精品国产免费直播| 品成人欧美大片久久国产欧美| 亚洲国产精久久久久久久| 国产精品免费看久久久香蕉| 9999国产精品欧美久久久久久| 麻豆精品久久精品色综合| 久久国产精品-国产精品| 久久精品国产一区二区三区日韩| 国产精品久久久久久福利69堂| 精品久久777| 国内精品久久久久久久coent| 7国产欧美日韩综合天堂中文久久久久 |