• <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>

            zoj3621

            http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3621

            Factorial Problem in Base K

            Time Limit: 2 Seconds      Memory Limit: 65536 KB

            How many zeros are there in the end of s! if both s and s! are written in base k which is not necessarily to be 10? For general base, the digit order is 0-9,A-Z,a-z(increasingly), for example F4 in base 46 is actually 694 in base 10,and f4 in base 46 is 1890 in base 10.

            Input

            There are multiple cases(less than 10000). Each case is a line containing two integers s and k(0 ≤ s < 2^63, 2 ≤ k ≤ 62).

            Output

            For each case, output a single line containing exactly one integer in base 10 indicating the number of zeros in the end of s!.

            Sample Input

            101 2 12 7 

            Sample Output

            3 1 

            Author: ZHANG, Debing
            Contest: ZOJ Monthly, June 2012

            zoj月賽題目,數(shù)據(jù)超強(qiáng)
            那個(gè)求一個(gè)數(shù)n的階乘的因式分解中k的個(gè)數(shù)的寫的要精彩,才不會(huì)wa
            code

            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include
            <stdio.h>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            #define maxn 205
            using namespace std;
            int hash[300];
            char str[maxn*10];
            long long k;
            int fen[105];
            int num[105],num1;
            long long sum[105];
            long long tmp;
            #define pp printf("here\n")
            long long  change(char str[])
            {
                
            int i,len;
                
            long long res;
                len
            =strlen(str);
                res
            =0;
                
            for( i=0; i<len; i++)
                {
                    res
            =res*k+hash[str[i]];
                }
                
            return res;
            }
            void fenjie()
            {
                
            int i;
                
            long long tmpx=k;
                memset(fen,
            0,sizeof(fen));
                memset(num,
            0,sizeof(num));
                num1
            =0;
                
            for(i=2; i<=k; i++)
                {
                    
            if(tmpx%i==0)
                    {
                        num1
            ++;
                        fen[num1]
            =i;
                        
            while(tmpx%i==0//這個(gè)地方,一定注意啊
                        {
                            num[num1]
            ++;
                            tmpx
            =tmpx/i;
                        }
                    }
                    
            if(tmpx==1break;
                }
            }
            long long  min(long long a,long long  b)
            {
                
            return a<b?a:b;
            }
            long long  chuli()
            {
                
            int i;
                
            long long tmp1;
                
            long long sumn;
                
            long long xx;
                memset(sum,
            0,sizeof(sum));
                
            for( i=1; i<=num1; i++)
                    
            if(num[i]!=0&&fen[i]!=0)
                    {
                      
            //  printf("%d %d\n",fen[i],num[i]);
                        xx=fen[i];
                        sumn
            =0;
                        tmp1
            =tmp;
                        
            while(xx<=tmp1)
                        {
                            sumn
            =sumn+tmp1/xx;
                            tmp1
            =tmp1/xx;
                        }
                        sum[i]
            =sumn;
                    }
                
            long long res=sum[1]/num[1];
                
            for( i=2; i<=num1; i++)
                  
            //  if(num[i]!=0&&fen[i]!=0)
                        res=min(res,sum[i]/num[i]);
                
            return res;
            }
            int main()
            {
                
            int i;
                
            for( i=0; i<=9; i++)
                {
                    hash[i
            +'0']=i;
                    
            //printf("%c,%d\n",i+'0',i);
                }
                
            for( i=0; i<26; i++)
                {
                    hash[i
            +'A']=i+10;
                    
            // printf("%c,%d\n",i+'A',i+10);
                }
                
            for(i=0; i<26; i++)
                {
                    hash[i
            +'a']=i+36;
                    
            // printf("%c,%d\n",i+'a',i+36);
                }
                
            while(scanf("%s%d",str,&k)!=EOF)
                {
                    tmp
            =change(str);
                    
            // pp;
                    
            // printf("%I64u\n",tmp);
                    if(tmp!=0)
                    {
                        fenjie();
                        
            //   pp;
                      
            // for(i=1;i<=num1;i++)
                        
            //printf("%d %d\n",fen[i],num[i]);
                        long long  ans=chuli();
                        printf(
            "%lld\n",ans);
                    }
                    
            else
                    {
                        printf(
            "0\n");
                    }
                }
                
            return 0;
            }

            posted on 2012-07-30 21:49 jh818012 閱讀(129) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            久久香蕉国产线看观看猫咪?v| 精品久久人人爽天天玩人人妻| 国产成年无码久久久久毛片| 精品国产乱码久久久久久郑州公司| 久久久国产乱子伦精品作者| 久久96国产精品久久久| 国产精品VIDEOSSEX久久发布| 无码乱码观看精品久久| 久久久精品人妻一区二区三区四| 国产福利电影一区二区三区久久老子无码午夜伦不 | 国产ww久久久久久久久久| 久久久人妻精品无码一区| 大香伊人久久精品一区二区| 久久福利青草精品资源站免费| 久久青青草原亚洲av无码| 亚洲精品无码久久久久| 久久精品中文字幕有码| 国产精品免费看久久久| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久亚洲AV成人出白浆无码国产| 久久国产视屏| 国产精品久久成人影院| 亚洲中文字幕无码久久2020| 日本加勒比久久精品| 丰满少妇人妻久久久久久4| 久久精品国产AV一区二区三区| 国产—久久香蕉国产线看观看| 国产精品毛片久久久久久久| 亚洲国产精品久久久天堂| 一本色道久久88综合日韩精品| 99精品伊人久久久大香线蕉| 久久av无码专区亚洲av桃花岛| 亚洲精品无码久久毛片| 精品久久久久久国产免费了| 国产精品久久久久久福利69堂| 亚洲AV无码成人网站久久精品大| 精品无码人妻久久久久久| 亚洲午夜精品久久久久久浪潮| 国产美女久久精品香蕉69| 一本久久精品一区二区| 国产成人精品久久免费动漫|