Pagini recente » Cod sursa (job #81720) | Cod sursa (job #402499) | Cod sursa (job #1161646) | Cod sursa (job #1723052) | Cod sursa (job #3223963)
#include <fstream>
using namespace std;
ifstream in("pascal.in");
ofstream out("pascal.out");
int n, d, ans;
int fact[5000005];
//fact[i] = cati d avem in descompunere lui factorial[i]
int main()
{
in>>n>>d;
int x;
for(int i = 2; i<=n; i++)
{
fact[i] = fact[i - 1];
if(d == 4)
{
x = i;
while(x % 2 == 0)
{
fact[i]++;
x /= 2;
}
}
else if(d == 6)
{
x = i;
while(x % 3 == 0)
{
fact[i]++;
x /= 3;
}
}
else
{
x = i;
while(x % d == 0)
{
fact[i]++;
x /= d;
}
}
}
if(d == 4)
{
while(1);
int nr;
for(int j = 0; j<=n; j++)
{
nr = fact[n] - fact[j] - fact[n - j];
nr /= 2;
if(nr > 0)
{
ans++;
//out<<j<<" -> "<<nr<<'\n';
}
}
}
else
{
int nr;
for(int j = 0; j<=n; j++)
{
nr = fact[n] - fact[j] - fact[n - j];
if(nr > 0)
{
ans++;
//out<<j<<" -> "<<nr<<'\n';
}
}
}
out<<ans;
return 0;
}