您的位置:首页 > 其它

Bzoj3309 DZY Loves Math

2017-06-07 16:35 246 查看

Time Limit: 20 Sec  Memory Limit: 512 MB
Submit: 992  Solved: 589

Description

对于正整数n,定义f(n)为n所含质因子的最大幂指数。例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0。
给定正整数a,b,求sigma(sigma(f(gcd(i,j)))) (i=1..a, j=1..b)。

Input

第一行一个数T,表示询问数。
接下来T行,每行两个数a,b,表示一个询问。

Output

对于每一个询问,输出一行一个非负整数作为回答。

Sample Input

4
7558588 9653114
6514903 4451211
7425644 1189442
6335198 4957

Sample Output

35793453939901
14225956593420
4332838845846
15400094813

HINT

【数据规模】

T<=10000

1<=a,b<=10^7


Source

 

莫比乌斯反演 脑洞题

题解传送门http://blog.csdn.net/sdfzyhx/article/details/72854335

 

/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#define LL long long
using namespace std;
const int mxn=10000010;
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int pri[mxn],cnt;
int mu[mxn],last[mxn],w[mxn],g[mxn];
bool vis[mxn];
LL smm[mxn];
void init(){
mu[1]=1;
for(int i=2;i<mxn;i++){
if(!vis[i]){
pri[++cnt]=i;last[i]=1;w[i]=1;
mu[i]=-1;g[i]=1;
}
for(int j=1;j<=cnt && pri[j]*i<mxn;j++){
int tmp=pri[j]*i;
vis[tmp]=1;
if(i%pri[j]==0){
last[tmp]=last[i];
w[tmp]=w[i]+1;
mu[tmp]=0;
if(last[tmp]==1) g[tmp]=1;
else    if(w[last[tmp]]==w[tmp])g[tmp]=-g[last[tmp]];
else g[tmp]=0;
break;
}
last[tmp]=i;
mu[tmp]=-mu[i];
w[tmp]=1;
g[tmp]=(w[i]==1)?(-g[i]):0;
}
}
for(int i=1;i<mxn;i++)smm[i]=smm[i-1]+g[i];
return;
}
int a,b;
void solve(){
if(a>b)swap(a,b);
LL ans=0;
for(int i=1,pos;i<=a;i=pos+1){
pos=min(a/(a/i),b/(b/i));
ans+=(smm[pos]-smm[i-1])*(LL)(a/i)*(b/i);
}
printf("%lld\n",ans);
return;
}
int main(){
//    freopen("in.txt","r",stdin);
init();
int T=read();
while(T--){
a=read();b=read();
solve();
}
return 0;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: