BZOJ 3309: DZY Loves Math 莫比乌斯反演+打表
有一个神奇的技巧——打表
code:
#include <bits/stdc++.h>
#define N 10000007
#define ll long long
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int cnt;
int vis[N],prime[N],g[N],mu[N],nump[N],minp[N],qp[N];
void Initialize()
{
int i,j;
mu[1]=1;
for(i=2;i<N;++i)
{
if(!vis[i])
{
prime[++cnt]=i;
nump[i]=1;
minp[i]=i;
qp[i]=i;
g[i]=1;
}
for(j=1;j<=cnt&&prime[j]*i<N;++j)
{
vis[i*prime[j]]=1;
int k=i*prime[j];
if(i%prime[j])
{
nump[k]=1;
qp[k]=minp[k]=prime[j];
if(nump[i]==1) g[k]=-g[i];
}
else
{
nump[k]=nump[i]+1;
minp[k]=prime[j];
qp[k]=qp[i]*prime[j];
if(k==qp[k]) g[k]=1;
else if(nump[k]==nump[k/qp[k]]) g[k]=-g[k/qp[k]];
break;
}
}
}
for(i=2;i<N;++i) g[i]+=g[i-1];
}
void solve(int a,int b)
{
if(a>b) swap(a,b);
int i,j;
ll ans=0ll;
for(i=1;i<=a;i=j+1)
{
j=min(a/(a/i),b/(b/i));
ans=ans+(ll)(a/i)*(b/i)*(g[j]-g[i-1]);
}
printf("%lld\n",ans);
}
int main()
{
// setIO("input");
Initialize();
int i,j,T;
scanf("%d",&T);
while(T--)
{
int a,b;
scanf("%d%d",&a,&b);
solve(a,b);
}
return 0;
}
BZOJ 3309: DZY Loves Math 莫比乌斯反演+打表的更多相关文章
- bzoj 3309 DZY Loves Math 莫比乌斯反演
DZY Loves Math Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1303 Solved: 819[Submit][Status][Dis ...
- BZOJ 3309 DZY Loves Math ——莫比乌斯反演
枚举$d=gcd(i,j)$ 然后大力反演 ——来自Popoqqq的博客. 然后大力讨论后面的函数的意义即可. http://blog.csdn.net/popoqqq/article/details ...
- bzoj 3309 DZY Loves Math —— 莫比乌斯反演+数论分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 凭着上课所讲和与 Narh 讨论推出式子来: 竟然是第一次写数论分块!所以迷惑了半天: ...
- BZOJ 3309: DZY Loves Math [莫比乌斯反演 线性筛]
题意:\(f(n)\)为n的质因子分解中的最大幂指数,求\(\sum_{i=1}^n \sum_{j=1}^m f(gcd(i,j))\) 套路推♂倒 \[ \sum_{D=1}^n \sum_{d| ...
- 【BZOJ】3309: DZY Loves Math 莫比乌斯反演优化
3309: DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007) ...
- ●BZOJ 3309 DZY Loves Math
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...
- BZOJ 3309: DZY Loves Math
3309: DZY Loves Math Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 761 Solved: 401[Submit][Status ...
- 【BZOJ3309】DZY Loves Math 莫比乌斯反演+线性筛(好题)
[BZOJ3309]DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10 ...
- 【BZOJ3309】DZY Loves Math - 莫比乌斯反演
题意: 对于正整数n,定义$f(n)$为$n$所含质因子的最大幂指数.例如$f(1960)=f(2^3 * 5^1 * 7^2)=3$,$f(10007)=1$,$f(1)=0$. 给定正整数$a,b ...
随机推荐
- Intellij IDEA最全的热键表(default keymap)
Editing Ctrl + Space Basic code completion (the name of any class, method or variable) Ctrl + Shift ...
- windows平台上编译mongdb-cxx-driver
编译方法见以下链接,写的非常详细 http://www.pianshen.com/article/9722211716/ 我的编译环境和编译工具如下: 环境:win7或者win10,都试过,没有任何区 ...
- Linux下which、whereis、locate、find命令作用
1 which 查看可执行文件的位置,也可以找到命令别名 2 whereis 查看文件的位置 3 locate 系统数据库查找文件位置,数据库大约每天更新一次 4 find 根据查找条件,搜寻硬盘查询 ...
- getElementsByClassName兼容 封装
众所周知,JS获取DOM有个getElementsByClassName,非常方便,但是呢,为了兼容某些浏览器(你懂的).只能 进行封装下了.解决方法如下 <!DOCTYPE html> ...
- property Alternative forms propretie
property Alternative forms propretie English English Wikipedia has articles on: Property (disambigua ...
- Building Objective-C static libraries with categories
Q: How do I fix "selector not recognized" runtime exceptions when trying to use category m ...
- MVC、MVP及MVVM之间的关系
介绍 写这篇随笔完全是为了加深自己的印象,毕竟写比看能获得得更多,另外本人对这三种模式的认识还是浅薄的,有待在以后的工作学习中有更深入的理解,因此不免会有误解,这里推荐大家阅读廖雪峰关于MVVM的介绍 ...
- nrm 工具的使用
一.什么是nrm? 这是官方的原话: 开发的npm registry 管理工具 nrm, 能够查看和切换当前使用的registry, 最近NPM经常 down 掉, 这个还是很有用的哈哈 顾名思义,就 ...
- MySQL Replication--复制延迟03--Seconds_Behind_Master计算
Seconds_Behind_Master计算原理 当从库上复制IO进程和复制SQL进程正常运行,且SQL线程处于执行状态而非等待IO进程同步BINLOG时,复制延迟时间计算如下: 复制延迟时间(Se ...
- springboot注解@NotNull,@NotBlank,@Valid自动判定空值
一.前言 搭建springboot项目,我们都是采用的Restful接口,那么问题来了,当前端调用接口或者是其他项目调用时,我们不能单一靠调用方来控制参数的准确性,自己也要对一些非空的值进行判定. 二 ...