Pagini recente » Cod sursa (job #1932053) | Cod sursa (job #2457174)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("pascal.in");
ofstream fout("pascal.out");
int n;
struct boi{
int d, p, top;
int f1, f2;
};
int ch[6] = {0, 0, 0, 1, 0, 2};
int churro[3][5000041];
void gchurro(int n)
{
int p = n;
while(p <= n){
for(int i = p; i <= n; i += p){
churro[ch[n]][i]++;
}
p *= n;
}
}
int susta(int a, int d)
{
int p = d, r = 0;
while(p <= a){
r += a/p;
p *= d;
}
return r;
}
int susta_reloaded(int a, int d)
{
int r = 0;
while(a % d == 0){
a /= d;
r++;
}
return r;
}
vector<boi> bois;
void release_bois(int d)
{
for(int i = 2; d > 1; i++){
boi b;
b.d = i;
b.p = 0;
while(d % i == 0){
b.p++;
d /= i;
}
if(b.p != 0){
gchurro(b.d);
b.top = susta(n, b.d);
b.f1 = 0;
b.f2 = b.top;
bois.push_back(b);
}
}
}
int fact(int n, int st = 2)
{
int r = 1;
for(int i = st; i <= n; i++){
r *= i;
}
return r;
}
int comb(int n, int k)
{
return fact(n, k+1) / fact(n-k);
}
bool big_brain(int i, int bi)
{
boi & b = bois[bi];
int d = b.d;
b.f1 += churro[ch[d]][i];
b.f2 -= churro[ch[d]][n-i+1];
int idk = b.top - (b.f1+b.f2);
return idk >= b.p;
}
int main()
{
int d;
fin >> n >> d;
release_bois(d);
int sol = 0;
for(int i = 1; i <= n/2; i++){
bool good = true;
for(int j = 0; j < bois.size(); j++){
good &= big_brain(i, j);
}
if(good){
if(n % 2 == 0 && i == n/2){
sol += 1;
}else{
sol += 2;
}
}
}
fout << sol;
return 0;
}