Cod sursa(job #3223963)
Utilizator | Data | 14 aprilie 2024 11:09:49 | |
---|---|---|---|
Problema | Pascal | Scor | 30 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 1.45 kb |
#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;
}