SPOJ 26108 TRENDGCD - Trending GCD
Discription
Problem statement is simple. Given A and B 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.
T 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的更多相关文章
- 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 ...
- SPOJ - PGCD Primes in GCD Table(莫比乌斯反演)
http://www.spoj.com/problems/PGCD/en/ 题意: 给出a,b区间,求该区间内满足gcd(x,y)=质数的个数. 思路: 设f(n)为 gcd(x,y)=p的个数,那么 ...
- * SPOJ PGCD Primes in GCD Table (需要自己推线性筛函数,好题)
题目大意: 给定n,m,求有多少组(a,b) 0<a<=n , 0<b<=m , 使得gcd(a,b)= p , p是一个素数 这里本来利用枚举一个个素数,然后利用莫比乌斯反演 ...
- bzoj 2818: Gcd GCD(a,b) = 素数
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1566 Solved: 691[Submit][Status] Descript ...
- 【HDU4947】GCD Array (莫比乌斯反演+树状数组)
BUPT2017 wintertraining(15) #5H HDU- 4947 题意 有一个长度为l的数组,现在有m个操作,第1种为1 n d v,给下标x 满足gcd(x,n)=d的\(a_x\ ...
- spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- 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 ...
- 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); 现 ...
- 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 ...
随机推荐
- ios之UIPageControl
分页控件是一种用来取代导航栏的可见指示器,方便手势直接翻页,最典型的应用便是iPhone的主屏幕,当图标过多会自动增加页面,在屏幕底部你会看到原点,用来只是当前页面,并且会随着翻页自动更新. 一.创建 ...
- 用Python写一个小爬虫吧!
学习了一段时间的web前端,感觉有点看不清前进的方向,于是就写了一个小爬虫,爬了51job上前端相关的岗位,看看招聘方对技术方面的需求,再有针对性的学习. 我在此之前接触过Python,也写过一些小脚 ...
- (63)zabbix low-level discover zabbix批量部署必备
1. 概述 <zabbix发现配置>server通过配置好的规则,自动添加host.group.template <zabbix Active agent自动注册>与disco ...
- 蓝牙学习 (7) - raspberrryPi 扫描TI sensorTag
前面几篇分别简单涉及了 raspberryPi上bluez BLE sniffer TI SensorTag https://blog.csdn.net/feiwatson/article/detai ...
- TSOJ--方格上的路径
题目描述: 试求 n × m 的方格图形中,从点 (0, 0) 到点 (n, m) 的最短路径数目. 输入描述: 有多组测试数据.输入的第一行为一个正整数 N,表示接下来有 N 组测试数据. 在接下来 ...
- 安装elk,日志采集系统
#elasticsearch安装 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux ...
- HDU 3341 Lost's revenge
Lost's revenge Time Limit: 5000ms Memory Limit: 65535KB This problem will be judged on HDU. Original ...
- BNUOJ 4215 最长公共连续子序列
最长公共连续子序列 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class ...
- hdu 4251 The Famous ICPC Team Again划分树入门题
The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 利用ps,grep,kill联合杀掉相关进程
#!/bin/sh . "./set-server-env.sh" 这里是输出ps -ef |grep java 结果的第二列的内容然后通过xargs传递给kill -9,其实第二 ...