#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll findZero(ll n, ll p)
{
ll c = 0, r = p;
while(r <= n)
{
c += (n/r);
r = r*p;
}
return c;
}
vector<pair<int, int>> primeFactorsofB(ll b)
{
vector<pair<int, int>> ans;
int i;
for(i=2;b != 1;i++)
{
if(b%i == 0)
{
int c = 0;
while(b%i == 0)
{
b = b/i;
c++;
}
ans.push_back(make_pair(i, c));
}
}
return ans;
}
ll largestZeroofB(ll n, ll b)
{
vector<pair<int, int>> vec;
vec = primeFactorsofB(b);
ll ans = INT_MAX;
int i;
for(i=0;i<vec.size();i++)
ans = min(ans, (findZero(n, vec[i].first)/vec[i].second));
return ans;
}
int main()
{
ll a, b;
while(cin >> a >> b)
{
ll c = largestZeroofB(a, b);
ll i, t;
double sum = 0;
for(i=1;i<=a;i++)
{
sum += log10(i)/log10(b);
}
t = floor(sum) + 1;
cout << c << " " << t << endl;
}
return 0;
}
#define ll long long int
using namespace std;
ll findZero(ll n, ll p)
{
ll c = 0, r = p;
while(r <= n)
{
c += (n/r);
r = r*p;
}
return c;
}
vector<pair<int, int>> primeFactorsofB(ll b)
{
vector<pair<int, int>> ans;
int i;
for(i=2;b != 1;i++)
{
if(b%i == 0)
{
int c = 0;
while(b%i == 0)
{
b = b/i;
c++;
}
ans.push_back(make_pair(i, c));
}
}
return ans;
}
ll largestZeroofB(ll n, ll b)
{
vector<pair<int, int>> vec;
vec = primeFactorsofB(b);
ll ans = INT_MAX;
int i;
for(i=0;i<vec.size();i++)
ans = min(ans, (findZero(n, vec[i].first)/vec[i].second));
return ans;
}
int main()
{
ll a, b;
while(cin >> a >> b)
{
ll c = largestZeroofB(a, b);
ll i, t;
double sum = 0;
for(i=1;i<=a;i++)
{
sum += log10(i)/log10(b);
}
t = floor(sum) + 1;
cout << c << " " << t << endl;
}
return 0;
}
Comments
Post a Comment