UVA-10061

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <sstream>
using namespace std;
int x,y;
int f1(){
    int da=2,xx=y,i=2,count1=0;
    while (xx>1)
    {
        if(xx%i==0){
            xx=xx/i;
            da=i;
            count1++;
        }else{
            i++;
            count1=0;
        }
    }
    int count2=0;
    for(i=2;i<=x;i++){
        int p=i;
        while (p>1)
        {
            if(p%da==0){
                p=p/da;
                count2++;
            }else break;
        }
    }
    return count2/count1;
}
// 首先计算位数,log(n)/log(b) + 1就是n在b进制下有多少位,而log有个公式就是log(M×N) = logM + logN,
//n! 的位数用公式可以化为( log(1) + log(2) +...+log(n) ) / log(b) + 1,为了精确再加 10^-6。
int f2(){
    double s=0;
    for(int i=2;i<=x;i++){
        s+=log(i);
    }
    s=s/log(y)+1;
    //cout<<s<<endl;
    return int(s);
}
int main(){
    while (cin>>x>>y)
    {
        cout<<f1()<<" "<<f2()<<endl;
    }
    return 0;
}

 

posted @ 2020-03-04 21:35  西伯利亚挖土豆  阅读(76)  评论(0编辑  收藏  举报