日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

zoj 3621 Factorial Problem in Base K 数论 s!后的0个数

發布時間:2023/12/19 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 zoj 3621 Factorial Problem in Base K 数论 s!后的0个数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Factorial Problem in Base K

Time Limit: 20 Sec??Memory Limit: 256 MB

題目連接

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

Description

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

HINT

題意

給你個在k進制下的數S,然后求S!在K進制下,有多少個末尾0
?

題解:

首先在10進制下,我們是怎么做的?我們先對10進行了質因數分解,分解成了2和5,然后我們就統計s!中,2和5各有多少個,然后取最少的就好了

就這樣,我們先對k進行質因數分解,然后我們取最少個數就好了

代碼:

?

//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 200001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() {ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } inline void P(int x) {Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts(""); } //**************************************************************************************string s; int n; const int p[18]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61}; int a[30]; int main() {while(cin>>s>>n){memset(a,0,sizeof(a));ll tmp=0;ll k=1;for(int i=s.size()-1;i>=0;i--){if(s[i]<='9'&&s[i]>='0')tmp+=(s[i]-'0')*k;else if(s[i]<='Z'&&s[i]>='A')tmp+=(s[i]-'A'+10)*k;else tmp+=(s[i]-'a'+36)*k;k*=n;}for(int i=0;i<18;i++){while(n%p[i]==0&&n>0){n/=p[i];a[i]++;}}ll ans=(1LL<<63)-1;for(int i=0;i<18;i++){ll now=tmp,tot=0;while(now>0){now/=p[i];tot+=now;}if(a[i]>0)ans=min(ans,tot/a[i]);}printf("%lld\n",ans);}}

?

轉載于:https://www.cnblogs.com/qscqesze/p/4539970.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的zoj 3621 Factorial Problem in Base K 数论 s!后的0个数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。