#include<algorithm>
using namespace std;
int r,d,sol;
int fact(int x,int y){
int exp;
for(exp=0; x; exp+=x/=y);
return exp;}
void solve(){
int i,s0,s1,x02,x12,x22,x03,x13,x23;
scanf("%d%d",&r,&d);
if(d==6){
if(r%2==0){
for(i=0; i<r/2; ++i){
x02=fact(r,2);
x12=fact(i,2);
x22=fact(r-i,2);
x03=fact(r,3);
x13=fact(i,3);
x23=fact(r-i,3);
s0=x02-x12-x22;
s1=x03-x13-x23;
if(s0>0&&s1>0)
sol+=2;}
x02=fact(r,2);
x12=fact(r/2,2);
x03=fact(r,3);
x13=fact(r/2,3);
s0=x02-2*x12;
s1=x03-2*x13;
if(s0>0&&s1>0)
++sol;}
else{
for(i=0; i<=r/2; ++i){
x02=fact(r,2);
x12=fact(i,2);
x22=fact(r-i,2);
x03=fact(r,3);
x13=fact(i,3);
x23=fact(r-i,3);}
s0=x02-x12-x22;
s1=x03-x13-x23;
if(s0>0&&s1>0)
sol+=2;}}
else if(d==4){
if(r%2==0){
for(i=0; i<r/2; ++i){
x02=fact(r,2);
x12=fact(i,2);
x22=fact(r-i,2);
s0=x02-x12-x22;
if(s0>1)
sol+=2;}
x02=fact(r,2);
x12=fact(r/2,2);
s0=x02-2*x12;
if(s0>1)
++sol;}
else{
for(i=0; i<=r/2; ++i){
x02=fact(r,2);
x12=fact(i,2);
x22=fact(r-i,2);}
s0=x02-x12-x22;
if(s0>1)
sol+=2;}}
else{
if(r%2==0){
for(i=0; i<r/2; ++i){
x02=fact(r,d);
x12=fact(i,d);
x22=fact(r-i,d);
s0=x02-x12-x22;
if(s0>0)
sol+=2;}
x02=fact(r,d);
x12=fact(r/2,d);
x22=fact(r/2+1,d);
s0=x02-x12-x22;
if(s0>0)
++sol;}
else{
for(i=0; i<=r/2; ++i){
x02=fact(r,d);
x12=fact(i,d);
x22=fact(r-i,d);}
s0=x02-x12-x22;
if(s0>0)
sol+=2;}}
printf("%d",sol);}
int main(){
freopen("pascal.in","r",stdin);
freopen("pascal.out","w",stdout);
solve();
return 0;}