Pagini recente » Cod sursa (job #2111105) | Cod sursa (job #220548) | Cod sursa (job #3211429) | Cod sursa (job #2036642) | Cod sursa (job #1782524)
#include <cstdio>
using namespace std;
short a[5000000];
int n, d;
inline int Legendre(int X, int IMP){
int Sol = 0;
long long L = IMP;
while(L <= X){
Sol = Sol + X / L;
L *= (long long) IMP;
}
return Sol;
}
int main()
{
freopen("pascal.in", "r", stdin);
freopen("pascal.out", "w", stdout);
scanf("%d%d", &n, &d);
a[0] = 1;
int Sol = 0;
int A2 = Legendre(n, 2), A3 = Legendre(n, 3);
for(int j = 1; j <= n / 2 ; ++j){
int D2 = A2 - Legendre(n - j, 2) - Legendre(j, 2);
int D3 = A3 - Legendre(n - j, 3) - Legendre(j, 3);
if(d == 2){
if(D2 > 0) ++Sol;
continue ;
}
if(d == 3){
if(D3 > 0) ++Sol;
continue ;
}
if(d == 6){
if(D2 && D3) ++ Sol;
continue ;
}
}
if(n % 2 == 1)
printf("%d", Sol * 2 );
else
printf("%d", Sol * 2 - 1);
}