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. 使用Auto Layout中的VFL(Visual format language)--代码实现自动布局

    使用Auto Layout中的VFL(Visual format language)--代码实现自动布局 2014-12-09 10:56 编辑: zhiwupei 分类:iOS开发 来源:机智的新手 ...

  2. tkinter学习-菜单与画布

    阅读目录 Menu 菜单控件 Menubutton 菜单按钮控件 OptionMenu 选项菜单 Canvas 画布控件 Menu: 说明:菜单控件,显示菜单栏,下拉菜单和弹出菜单 属性:创建一个顶级 ...

  3. Web框架之Django_08 重要组件(form组件、cookie和session组件)

    摘要: form组件 cookie组件 session组件 一.form组件 form介绍我们之前在html页面中利用form表单向后端提交数据时候,都需要对用户的输入进行校验,比如校验用户是否输入正 ...

  4. LeetCode(91) Decode Ways

    题目 A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A ...

  5. 算法学习记录-图(DFS BFS)

    图: 目录: 1.概念 2.邻接矩阵(结构,深度/广度优先遍历) 3.邻接表(结构,深度/广度优先遍历) 图的基本概念: 数据元素:顶点 1.有穷非空(必须有顶点) 2.顶点之间为边(可空) 无向图: ...

  6. 【14】PNG,GIF,JPG的区别及如何选

    [14]PNG,GIF,JPG的区别及如何选 GIF: 8位像素,256色 无损压缩 支持简单动画 支持boolean透明 适合简单动画 JPEG: 颜色限于256 有损压缩 可控制压缩质量 不支持透 ...

  7. 【03】const

    [03]const 魔芋总结: 1,声明的是常量,一经声明,不得修改.必须声明的同时并赋值.否则报错. 2,只在声明所在的块级作用域内有效. 3,const命令声明的常量也是不提升,同样存在暂时性死区 ...

  8. cf950f Curfew

    神贪心--写了一个晚上加一个早上. 先考虑只有一个宿管的情况. 首先,如果这个宿舍人多了,多余的人就跑到下一个宿舍.(如果这是最后一个宿舍的话,多的就躺床底下) 如果这个宿舍人少了,但是能从别的宿舍调 ...

  9. 二、harbor部署之部署harbor

    1 harbor部署之安装docker 1.yum install -y docker #安装docker 2 harbor部署之安装docker-compose 1.首先检查centos有没有安装p ...

  10. matlab调用自己写的函数时报错: reference to a cleared variable

    原因是在自己写的函数中加了clear. 解决办法:自己定义的函数中不能加clear,可以加clc;