# [POI2007]Zap

f(k)不好求，但是F(k)比较好求，它等于(a/k)*(b/k)

f(k)=sigma(F(d/k)*μ(d)) (k|d)

f(1)=sigma(F(d)*μ(d))(1<=d<=min(a,b))

//Lib
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
//Macro
#define	rep(i,a,b)	for(int i=a,tt=b;i<=tt;++i)
#define	drep(i,a,b)	for(int i=a,tt=b;i>=tt;--i)
#define	erep(i,e,x)	for(int i=x;i;i=e[i].next)
#define	irep(i,x)	for(__typedef(x.begin()) i=x.begin();i!=x.end();i++)
#define	sqr(x)	((x)*(x))
#define	pb	push_back
#define	PS	system("pause");
typedef	long long	ll;
typedef	pair<int,int>	pii;
const int oo=~0U>>1;
const double inf=1e100;
const double eps=1e-6;
string name="", in=".in", out=".out";
//Var
int u[50008],n,ans;
int calc(int x)
{
int ret=1;
for(int i=2;i*i<=x;i++)
if(x%i==0)
{
x/=i,ret*=-1;
if(x%i==0)return 0;
}
if(x!=1)ret*=-1;
return ret;
}
void Work()
{
rep(i,1,50000)
u[i]=u[i-1]+calc(i);
scanf("%d",&n);int len,a,b,d;
rep(i,1,n)
{
scanf("%d%d%d",&a,&b,&d);
if(a>b)swap(a,b);
a/=d;b/=d;ans=0;
rep(pos,1,a)
{
len=min(a/(a/pos),b/(b/pos))-pos;
ans+=(a/pos)*(b/pos)*(u[pos+len]-u[pos-1]);
pos+=len;
}
cout<<ans<<endl;
}
}
int main()
{
//	freopen((name+in).c_str(),"r",stdin);
//	freopen((name+out).c_str(),"w",stdout);
//	Init();
Work();
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120