#include <iostream>
#include <fstream>
using namespace std;
int R, D;
int sol;
int nrdiv;
int exp[10];
struct DIV
{
int d, e;
};
DIV a[3];
inline void Read()
{
ifstream f ("pascal.in");
f>>R>>D;
f.close();
}
inline void CreateDivsList()
{
switch(D)
{
case 2:
nrdiv = 1;
a[1].d = 2;
a[1].e = 1;
break;
case 3:
nrdiv = 1;
a[1].d = 3;
a[1].e = 1;
break;
case 4:
nrdiv = 1;
a[1].d = 2;
a[1].e = 2;
break;
case 5:
nrdiv = 1;
a[1].d = 5;
a[1].e = 1;
break;
case 6:
nrdiv = 2;
a[1].d = 2;
a[1].e = 1;
a[2].d = 3;
a[2].e = 1;
break;
}
}
inline void Solve()
{
CreateDivsList();
int i, lim = (R+1) / 2 - 1, j, x;
bool ok;
for (i = 1; i<=lim; ++i)
{
/// * (R-i) / (i+1)
x = R-(i-1);
for (j=1; j<=nrdiv; ++j)
{
while (x%a[j].d == 0)
{
++exp[a[j].d];
x/=a[j].d;
}
}
x = i;
for (j=1; j<=nrdiv; ++j)
{
while (x%a[j].d == 0)
{
--exp[a[j].d];
x/=a[j].d;
}
}
ok = true;
for (j=1; j<=nrdiv; ++j)
{
if (exp[a[j].d] < a[j].e)
ok = false;
}
if (ok)
sol += 2;
}
if (R % 2 == 0)
{
x = R-(i-1);
for (j=1; j<=nrdiv; ++j)
{
while (x%a[j].d == 0)
{
++exp[a[j].d];
x/=a[j].d;
}
}
x = i;
for (j=1; j<=nrdiv; ++j)
{
while (x%a[j].d == 0)
{
--exp[a[j].d];
x/=a[j].d;
}
}
ok = true;
for (j=1; j<=nrdiv; ++j)
{
if (exp[a[j].d] < a[j].e)
ok = false;
}
if (ok)
++sol;
}
}
inline void Write()
{
ofstream g("pascal.out");
g<<sol<<"\n";
g.close();
}
int main()
{
Read();
Solve();
Write();
return 0;
}