bzoj 2694: Lcm
2694: Lcm
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 422 Solved: 220
[Submit][Status][Discuss]
Description
.jpg)
也就是说gcd(a, b)没有一个因子的次数>=2
Input
Output
Sample Input
2 4
3 3
6 5
8 3
Sample Output
28
233
178
HINT
HINT
T <= 10000
N, M<=4000000
#include<bits/stdc++.h>
#define ll long long
const int maxn=4000000;
const int ha=1<<30;
using namespace std;
int zs[maxn/5],t=0,T,n,m;
int low[maxn+5],f[maxn+5];
bool v[maxn+5]; inline int add(int x,int y){
x+=y;
return x>=ha?x-ha:x;
} inline void init(){
low[1]=f[1]=1;
for(int i=2;i<=maxn;i++){
if(!v[i]) zs[++t]=i,low[i]=i,f[i]=1-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]]) f[u]=f[i/low[i]]*-low[i];
else f[u]=0;
break;
}
low[u]=zs[j];
f[u]=f[i]*f[zs[j]];
}
} for(int i=1;i<=maxn;i++) f[i]=add(add(f[i],ha)*(ll)i%ha,f[i-1]);
} inline int solve(){
int an=0;
if(n>m) swap(n,m); for(int i=1,nx,ny,j;i<=n;i=j+1){
nx=n/i,ny=m/i,j=min(n/nx,m/ny);
an=add(an,((nx+1)*(ll)nx>>1)%ha*(ll)(((ny+1)*(ll)ny>>1)%ha)%ha*(ll)add(f[j],ha-f[i-1])%ha);
} return an;
} int main(){
init();
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
printf("%d\n",solve());
}
return 0;
}
bzoj 2694: Lcm的更多相关文章
- ●BZOJ 2694 Lcm
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2694 题解: 莫比乌斯反演 不难看出,造成贡献的(i,j)满足gcd(i,j)无平方因子. ...
- [bzoj] 2694 Lcm || 莫比乌斯反演
原题 定义整数a,b,求所有满足条件的lcm(a,b)的和: 1<=a<=A 1<=b<=B ∀n>1,n2†gcd(a,b)(即任意n>1,\(n^2\)不是gc ...
- BZOJ:4659&&BZOJ:2694: Lcm
Description 给出A,B,考虑所有满足l<=a<=A,l<=b<=B,且不存在n>1使得n^2同时整除a和b的有序数 对(a,b),求其lcm(a,b)之和.答 ...
- BZOJ 2694: Lcm [莫比乌斯反演 线性筛]
题意:求\(\sum\limits_{i=1}^n \sum\limits_{j=1}^m lcm(i,j)\ : gcd(i,j) 是sf 无平方因子数\) 无平方因子数?搞一个\(\mu(gcd( ...
- BZOJ 2694: Lcm 莫比乌斯反演 + 积性函数 + 线性筛 + 卡常
求 $\sum_{i=1}^{n}\sum_{j=1}^{m}lcm(i,j)\mu(gcd(i,j))^2$ $\Rightarrow \sum_{d=1}^{n}\mu(d)^2\sum_{i ...
- 【BZOJ】【2694】Lcm
数论/莫比乌斯反演/线性筛 题解:http://www.cnblogs.com/zyfzyf/p/4218176.html JZPTAB的加强版?感觉线性筛好像还是不怎么会啊……sad 题目记下来,回 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- bzoj 2154 莫比乌斯反演求lcm的和
题目大意: 表格中每一个位置(i,j)填的值是lcm(i,j) , 求n*m的表格值有多大 论文贾志鹏线性筛中过程讲的很好 最后的逆元我利用的是欧拉定理求解的 我这个最后线性扫了一遍,勉强过了,效率不 ...
- 【莫比乌斯反演】关于Mobius反演与lcm的一些关系与问题简化(BZOJ 2154 crash的数字表格&&BZOJ 2693 jzptab)
BZOJ 2154 crash的数字表格 Description 今天的数学课上,Crash小朋友学习了最小公倍数(Least Common Multiple).对于两个正整数a和b,LCM(a, b ...
随机推荐
- struts2的动态方法配置
动态方法调用配置 <package name="test" extends="struts-default"> <aciton name=&q ...
- Bootstrap 网格系统(Grid System)实例2
Bootstrap 网格系统(Grid System):堆叠水平,两种样式 <!DOCTYPE html><html><head><meta http-equ ...
- Broadcast BCM94322 用ubuntu修改ID
1.按这个教程的6楼做的http://bbs.pcbeta.com/viewthread-1324168-1-1.html.注意我先下载 的是ubuntu9.05版本,做U盘启动进live 模式,43 ...
- 697. Degree of an Array@python
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the ma ...
- ThreadLocal类使用说明
ThreadLocal类用于创建一个线程本地变量 在Thread中有一个成员变量ThreadLocals,该变量的类型是ThreadLocalMap,也就是一个Map,它的键是threadLo ...
- service worker 消息推送
https://developers.google.com/web/fundamentals/codelabs/push-notifications/?hl=en 首先下载源码: git clone ...
- 三段式fsm
1.状态转移的always中CS,同步ouput的always中NS. 2.3段fsm vs 2段fsm:output逻辑是组合逻辑和同步时序逻辑(消除里不稳的和毛刺). 3.3段fsm vs 1段f ...
- Django初学及mvt模型理解
Django是python语言用来做web项目的一个模板,创建Django项目之后会自动生成models,views和templates文件夹,又叫mvt框架 文件结构如下: Models:其中mod ...
- python的部分内置函数
内置函数思维导图:https://www.processon.com/mindmap/5c10ca52e4b0c2ee256ac034 内置函数 匿名函数 匿名函数统一的名字是:<lambda& ...
- go 本地安装 grpc-go
https://blog.csdn.net/code_segment/article/details/77461590 https://github.com/grpc/grpc-go git clon ...