zoj_3621 Factorial Problem in Base K
2013-05-30 22:02
363 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4745
//C++代码 #include<iostream> #include<cstring> #include<cctype> using namespace std; typedef long long LL; int main(){ string p; LL k; while(cin>>p>>k){ LL i,s=0,t=0,a[4],b[4]={0},c[4]={0}; for(i=0;i<p.length();i++){ s=s*k+p[i]-'0'-(isupper(p[i])? 7:0)-(islower(p[i])? 13:0); } for(i=2;i<=k;i++){ if(k%i==0){ while(k%i==0){ k/=i; b[t]++; } a[t++]=i; } } for(i=0;i<t;i++){ LL q=s; while(q){ q/=a[i]; c[i]+=q; } c[i]/=b[i]; } LL min=c[0]; for(i=1;i<t;i++){ if(c[i]<min) min=c[i]; } cout<<min<<endl; } return 0; }
相关文章推荐
- zoj 1525 || poj 1422 Air Raid
- 【解题报告】 ZOJ 3640 Help Me Escape - 期望dp
- zoj 3812
- ZOJ 3605 Find the Marble(dp)
- hdu 3788 zoj问题
- zoj 3543 Number String(DP)
- ZOJ 2588 Burning Bridges 求无向图的桥
- ZOJ 2433 Highways
- zoj 3171 The Hidden 7's DP
- ZOJ - 1001--A + B Problem
- ZOJ 1081 Points Within(点在多边形内判定)
- ZOJ 3872 Beauty of Array( DP思想 )
- zoj 1074 To the Max 最大子矩阵之和
- ZOJ 3551 Bloodsucker
- 【最大流】ZOJ-2788 Panic Room
- ZOJ - 1048 Financial Management
- zoj1457_Prime Ring Problem
- zoj 2840 File Searching
- ZOJ 3805 Machine
- zoj-3946-Highway Project【13th浙江省赛】【最短路】