# [BZOJ]2301: [HAOI2011]Problem b

Description

Input

Output

Sample Input
2
2 5 1 5 1
1 5 1 5 2
Sample Output
14
3

cal(x,y)表示求对于给定的整数x,y和k，有多少正整数对i,j，满足i<=x，j<=y，并且gcd(x,y)=k
cal的写法我在http://blog.csdn.net/qq_36368091/article/details/73925116中有写到过

#include <cstdio>
using namespace std;
inline int min(int a,int b)
{
return a<b?a:b;
}
inline void swap(int &a,int &b)
{
int t=a;a=b,b=t;return ;
}
inline char tc(void)
{
static char fl[1000000],*A=fl,*B=fl;
}
{
int a=0;static char c;
while((c=tc())<'0'||c>'9');
while(c>='0'&&c<='9')
a=a*10+c-'0',c=tc();
return a;
}

int n,tot,prim[25001],mu[50001],sum[50001],a,b,c,d,k,pos,ans;
char vis[50001];

inline void prepare(void)
{
mu[1]=1;
for (int i=2;i<=50000;++i)
{
if(!vis[i])
prim[++tot]=i,mu[i]=-1;
for (int j=1;j<=tot&&i*prim[j]<=50000;++j)
{
vis[i*prim[j]]=1;
if(i%prim[j]==0)
{
mu[i*prim[j]]=0;
break;
}
mu[i*prim[j]]=-mu[i];
}
}
for (int i=1;i<=50000;++i)
sum[i]=sum[i-1]+mu[i];
return ;
}

int cal(int n,int m)
{
if(n>m)swap(n,m);
ans=0;
for(int i=1;i<=n;i=pos+1)
pos=min(n/(n/i),m/(m/i)),ans+=(sum[pos]-sum[i-1])*(n/i)*(m/i);
return ans;
}

int main(void)
{
register int i;
}