#include<bits/stdc++.h>
using namespace std;
const unsigned L=101200;
typedef signed uu;
typedef signed long long ull;
#define out(x) cerr<<#x"="<<x<<endl
uu u[L],p[5555],pc;
uu a[5555];
vector<uu> c[5555];
ull cnt[L];
int main(){
	for(uu i=2;i<L;++i)if(!u[i]){
		for(uu j=i;j<L;j+=i)u[j]=i;
		p[pc++]=i;
	}
	for(uu n,x,m;scanf("%u%u",&n,&x)==2 && n && x;){
		ull ans=0;
		vector<uu> pos;
		unordered_map<uu, vector<uu> > chg;
		for(m=0;;++m){
			uu c=0,t=n,p=::p[m];
			for( ;t;)c+=(t/=p);
			if(c<x)break;
			a[m]=c/x;
			::c[m].clear();
			::c[m].push_back(1123456789);
			for(int j=1;j<=a[m];++j){
				pos.push_back(c/j);
				::c[m].push_back(c/j);
				chg[c/j].push_back(m);
			}
		}
		sort(pos.begin(),pos.end());
		pos.resize(unique(pos.begin(),pos.end())-pos.begin());
		ull ret=1;
		for(int j=0;j<m;++j)
			ret*=(1+a[j]);
		for(int i=0;i<pos.size();++i){
			uu y=pos[i];
			cnt[i]=ret;
			vector<uu> &v=chg[y];
			for(int j=0; j<v.size(); ++j){
				assert(ret%(1+a[v[j]])==0);
				ret/=1+a[v[j]];
				ret*=a[v[j]]--;
			}
		}
		cnt[pos.size()]=1;
		for(int i=0;i<pos.size();++i){
			cnt[i]-=cnt[i+1];
			ans+=cnt[i]*(cnt[i]-1)>>1;
		}
		cout << ans << "\n";
	}
}
