Pagini recente » Cod sursa (job #2552827) | Cod sursa (job #2131677) | Cod sursa (job #3144205) | Cod sursa (job #839523) | Cod sursa (job #2769177)
#include <fstream>
using namespace std;
ifstream f("pascal.in");
ofstream g("pascal.out");
int expp(int n, int p)
{
int e = 0;
while(n % p == 0)
{
e++;
n /= p;
}
return e;
}
int main()
{
int R, D, nrd = 0;
f >> R >> D;
//
if(R >= 2)
{
int ex2 = 0, ex3 = 0, ex5 = 0,
r2 = (R + 1) / 2;
//
while(D % 2 == 0) D /= 2, ex2++;
while(D % 3 == 0) D /= 3, ex3++;
while(D % 5 == 0) D /= 5, ex5++;
//
for(int k = 1; k < r2; k++)
{
ex2 -= expp(R - k + 1, 2) - expp(k, 2);
ex3 -= expp(R - k + 1, 3) - expp(k, 3);
ex5 -= expp(R - k + 1, 5) - expp(k, 5);
nrd += ex2 <= 0 && ex3 <= 0 && ex5 <= 0;
}
nrd *= 2;
if(R % 2 == 0)
{
ex2 -= expp(r2 + 1, 2) - expp(r2, 2);
ex3 -= expp(r2 + 1, 3) - expp(r2, 3);
ex5 -= expp(r2 + 1, 5) - expp(r2, 5);
nrd += ex2 <= 0 && ex3 <= 0 && ex5 <= 0;
}
}
g << nrd;
f.close();
g.close();
return 0;
}