Pagini recente » Cod sursa (job #191601) | Cod sursa (job #3264884) | Cod sursa (job #1803124) | Cod sursa (job #2175269) | Cod sursa (job #2795359)
#include <bits/stdc++.h>
#define N 2008
using namespace std;
ifstream fin("gfact.in");
ofstream fout("gfact.out");
int p, q;
void Citire()
{
fin >> p >> q;
}
int Pow( int x, int y )
{
if( x == 0 ) return 0;
if( x == 1 ) return 1;
if( y == 1 ) return x;
if( y == 0 ) return 1;
int p = Pow( x, y / 2 );
if( y % 2 == 1 ) return x * p * p;
else return p * p;
}
int howMany( int b, int p )
{
int k = log(b) / log(p);
return (b / 2) * ( ((Pow(p, k)) - 1) / (p - 1) );
}
int CB( int p, int q )
{
int st, dr;
int mid;
int sol = 0;
st = 0;
dr = p * q;
while( st <= dr )
{
mid = ( st + dr ) / 2;
if( howMany(mid, p) < q )
st = mid + 1;
else
sol = mid,
dr = mid - 1;
}
return sol;
}
void Rezolvare()
{
if( p == 1 )
{
fout << 1;
return;
}
int d, ct = 0;
int sol = 0;
while( p % 2 == 0 )
{
p /= 2;
ct++;
}
if( ct >= 0 )
sol += CB( 2, ct * q );
d = 3;
while( d * d <= p )
{
ct = 0;
while( d % d == 0 )
{
p /= d;
ct++;
}
if( ct != 0 )
sol += CB( d, ct * q );
d += 2;
}
if( p != 1 )
sol += CB( p, q );
fout << sol;
}
int main()
{
Citire();
Rezolvare();
return 0;
}