Discription

Problem statement is simple. Given and you need to calculate S(A,B) .

Here, f(n)=n, if n is square free otherwise 0. Also f(1)=1.

Input

The first line contains one integer T - denoting the number of test cases.

lines follow each containing two integers A,B.

Output

For each testcase output the value of S(A,B) mod 1000000007 in a single line.

Constraints

  • T <= 1000
  • 1 <= A,B <= 1000000

Example

Input:
3
42 18
35 1
20 25 Output:
306395
630
128819 提一波公因数,把f(x) 化成 μ^2(x) * x,再化简之后发现需要筛一个积性函数(推一推就好了),然后分块回答询问即可。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1000000;
const int ha=1000000007;
int G[maxn+5],t,zs[maxn/5],T,n,m,low[maxn+5];
bool v[maxn+5]; inline int add(int x,int y){
x+=y;
return x>=ha?x-ha:x;
} inline void init(){
G[1]=low[1]=1;
for(int i=2;i<=maxn;i++){
if(!v[i]) zs[++t]=i,G[i]=i-1,low[i]=i;
for(int j=1,u;j<=t&&(u=zs[j]*i)<=maxn;j++){
v[u]=1;
if(!(i%zs[j])){
low[u]=low[i]*zs[j];
if(v[low[i]]) G[u]=0;
else G[u]=G[i/low[i]]*(ll)(ha-zs[j])%ha;
break;
}
low[u]=zs[j],G[u]=G[i]*(ll)G[zs[j]]%ha;
}
} for(int i=1;i<=maxn;i++) G[i]=add(G[i-1],G[i]*(ll)i%ha*(ll)i%ha);
} inline int C(int x){
return (x*(ll)(x+1)>>1)%ha;
} inline int solve(int x,int y){
int ans=0;
for(int i=1,j,nx,ny;i<=x;i=j+1){
nx=x/i,ny=y/i,j=min(x/nx,y/ny);
ans=add(ans,C(nx)*(ll)C(ny)%ha*(ll)add(G[j],ha-G[i-1])%ha);
}
return ans;
} int main(){
init();
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
if(n>m) swap(n,m);
printf("%d\n",solve(n,m));
} return 0;
}

  

 

SPOJ 26108 TRENDGCD - Trending GCD的更多相关文章

  1. SPOJ LGLOVE 7488 LCM GCD Love (区间更新,预处理出LCM(1,2,...,n))

    题目连接:http://www.spoj.com/problems/LGLOVE/ 题意:给出n个初始序列a[1],a[2],...,a[n],b[i]表示LCM(1,2,3,...,a[i]),即1 ...

  2. SPOJ - PGCD Primes in GCD Table(莫比乌斯反演)

    http://www.spoj.com/problems/PGCD/en/ 题意: 给出a,b区间,求该区间内满足gcd(x,y)=质数的个数. 思路: 设f(n)为 gcd(x,y)=p的个数,那么 ...

  3. * SPOJ PGCD Primes in GCD Table (需要自己推线性筛函数,好题)

    题目大意: 给定n,m,求有多少组(a,b) 0<a<=n , 0<b<=m , 使得gcd(a,b)= p , p是一个素数 这里本来利用枚举一个个素数,然后利用莫比乌斯反演 ...

  4. bzoj 2818: Gcd GCD(a,b) = 素数

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1566  Solved: 691[Submit][Status] Descript ...

  5. 【HDU4947】GCD Array (莫比乌斯反演+树状数组)

    BUPT2017 wintertraining(15) #5H HDU- 4947 题意 有一个长度为l的数组,现在有m个操作,第1种为1 n d v,给下标x 满足gcd(x,n)=d的\(a_x\ ...

  6. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

  7. spoj 3871. GCD Extreme 欧拉+积性函数

    3871. GCD Extreme Problem code: GCDEX Given the value of N, you will have to find the value of G. Th ...

  8. spoj 3871 gcd extreme

    题目大意给出一个n,求sum(gcd(i,j),<i<j<=n); 可以明显的看出来s[n]=s[n-]+f[n]; f[n]=sum(gcd(i,n),<i<n); 现 ...

  9. SPOJ PGCD 4491. Primes in GCD Table && BZOJ 2820 YY的GCD (莫比乌斯反演)

    4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the results of ...

随机推荐

  1. NoSQL 之 Morphia 操作 MongoDB

    上两篇文章:http://www.cnblogs.com/hoojo/archive/2011/06/01/2066426.html http://www.cnblogs.com/hoojo/arch ...

  2. 全面解读Oracle同义词的概念作用、创建删除查看及Oracle的db link

    Oracle的同义词(synonyms)从字面上理解就是别名的意思,和视图的功能类似,就是一种映射关系. 在Oracle中对用户的管理是使用权限的方式来管理的,也就是说,如果我们想使用数据库,我们就必 ...

  3. PAT 乙级 1041

    题目 题目地址:PAT 乙级 1041 题解 这道题学到的东西恰好和1037中学到的东西相互补充,总结如下: 在之前的博文中我曾提到过——“结构体在函数内部对数据的操作不能赋给主函数中的实参,函数内部 ...

  4. 【css】修改placeholder 默认颜色

    html5为input添加了原生的占位符属性placeholder,高级浏览器都支持这个属性,例如: <input type="text" placeholder=" ...

  5. laravel使用总结(二)

    Mysql Eloquent 模型 新建Model 对应 表前缀 + 类名称 + s namespace App; use Illuminate\Database\Eloquent\Model; cl ...

  6. VS搭建一个WEB的简历第二天,,,最终目标写个好看的简历,再搭建一个自己脑海的网页

    VS做简历的第二天 第二天吸取了第一天的教训写的代码 第一天写的代码https://www.cnblogs.com/pythonywy/p/10816215.html,写了一堆错误T T 非常感谢Li ...

  7. Java集合之PriorityQueue

    PriorityQueue 定义 C++:priority_queue Java:PriorityQueue 创建与其基本操作 创建: PriorityQueue<Integer>=new ...

  8. 水题:UVa253-Cube painting

    Cube painting We have a machine for painting cubes. It is supplied with three different colors: blue ...

  9. Luogu3195 [HNOI2008]玩具装箱TOY (方程变形 + 斜率优化 )

    题意: 给出一个序列 {a[i]} 把其分成若干个区间,每个区间的价值为 W = (j − i + ∑ak(i<=k<=j) - L)​2 ,求所有分割方案中价值之和的最小值. 细节: 仔 ...

  10. PAT Basic 1070

    1070 结绳 给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连.每次串连后,原 ...