考虑对于一个进制循环小数
如果循环节为
那么这个数乘上后小数部分不变
那么就是
考虑这个中有解的条件即
又
所以就可以的到
枚举后可以得到
然后就可以愉快的递归了
时可以简单莫反后用杜教筛算前缀和整除分块
考虑最多只有个取值
所以复杂度为
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
//cs int mod=1e9+7;
//inline int add(int a,int b){return (a+=b)>=mod?(a-mod):a;}
//inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
//inline int mul(int a,int b){static ll r;r=1ll*a*b;return (r>=mod)?(r%mod):r;}
//inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
//inline void Dec(int &a,int b){a-=b,a+=a>>31&mod;}
//inline void Mul(int &a,int b){static ll r;r=1ll*a*b;a=(r>=mod)?(r%mod):r;}
//inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
//inline int Inv(int x){return ksm(x,mod-2);}
cs int N=1000005;
int mu[N],pr[N],tot;
bitset<N>vis;
inline void init(cs int len=N-5){
mu[1]=1;
for(int i=2;i<=len;i++){
if(!vis[i])pr[++tot]=i,mu[i]=-1;
for(int j=1,p;j<=tot&&i*pr[j]<=len;j++){
p=i*pr[j],vis[p]=1;
if(i%pr[j]==0)break;
mu[p]=-mu[i];
}
}
for(int i=1;i<=len;i++)mu[i]+=mu[i-1];
}
map<int,int> S;
inline int summu(int n){
if(n<=N-5)return mu[n];
if(S.count(n))return S[n];
int ret=1;
for(int i=2,j;i<=n;i=j+1){
j=n/(n/i);
ret-=(j-i+1)*summu(n/i);
}
return S[n]=ret;
}
struct node{
int n,m,k;
node(int a=0,int b=0,int c=0):n(a),m(b),k(c){}
friend inline bool operator <(cs node &a,cs node &b){
return a.n==b.n?(a.m==b.m?(a.k<b.k):a.m<b.m):a.n<b.n;
}
};
map<node,ll> s;
int n,m,k,fc[2005],cnt;
inline ll calc(int n,int m){
ll ret=0;if(n>m)swap(n,m);
for(int i=1,j;i<=n;i=j+1){
j=min(n/(n/i),m/(m/i));
ret+=1ll*(summu(j)-summu(i-1))*(n/i)*(m/i);
}
return ret;
}
inline ll calc(int n,int m,int k){
if(!n)return 0;
if(!m)return 0;
node p=node(n,m,k);
if(s.count(p))return s[p];
if(k==1)return s[p]=calc(n,m);
ll ret=0;
for(int i=1,d;i<=cnt&&fc[i]<=k;i++)
if(k%(d=fc[i])==0)ret+=(mu[d]-mu[d-1])*calc(m/d,n,d);
return s[p]=ret;
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
init();
n=read(),m=read(),k=read();
for(int i=1;i<=k;i++)if(mu[i]!=mu[i-1]&&k%i==0)fc[++cnt]=i;
cout<<calc(n,m,k)<<'
';
}