bzoj 3309 DZY Loves Math —— 莫比乌斯反演+数论分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309
凭着上课所讲和与 Narh 讨论推出式子来;
竟然是第一次写数论分块!所以迷惑了半天;
在预处理的筛中也犯了愚蠢的错误...总之全仰仗 Narh 提点了...
所以具体题解就看这里咯:https://www.cnblogs.com/Narh/p/9740786.html
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int const xn=1e7+;
int T,a[xn],b[xn],c[xn],tot,pri[xn],cnt;
ll s[xn];
bool vis[xn];
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return f?ret:-ret;
}
void init()
{
int mx=1e7;
for(int i=;i<=mx;i++)
{
if(!vis[i])a[i]=b[i]=c[i]=,pri[++cnt]=i;
if(a[i]==)s[i]=s[i-]+((c[i]&)?:-); else s[i]=s[i-];
for(int j=,k;j<=cnt&&(ll)i*pri[j]<=mx;j++)
{
vis[k=i*pri[j]]=;
if(i%pri[j])//新增pri[j]
{
if(!a[i]||(a[i]&&b[i]!=))a[k]=,b[k]=;
else a[k]=,b[k]=;
c[k]=c[i]+;
}
else
{
int w=k,t=;
while(w%pri[j]==)w/=pri[j],t++;
if(w==||(a[w]&&b[w]==t))a[k]=,b[k]=t;
else a[k]=,b[k]=;
c[k]=c[i];
}
}
}
}
int main()
{
T=rd(); init();
while(T--)
{
int n,m; n=rd(); m=rd();
ll ans=;
if(n>m)swap(n,m);
for(int i=,nxt;i<=n;i=nxt+)
ans+=(ll)(n/i)*(m/i)*(s[nxt=min(n/(n/i),m/(m/i))]-s[i-]);
printf("%lld\n",ans);
}
return ;
}
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 [莫比乌斯反演 线性筛]
题意:\(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 莫比乌斯反演+打表
有一个神奇的技巧——打表 code: #include <bits/stdc++.h> #define N 10000007 #define ll long long #define se ...
- 【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 2820] YY的gcd(莫比乌斯反演+数论分块)
[BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块) 题面 给定N, M,求\(1\leq x\leq N, 1\leq y\leq M\)且gcd(x, y)为质数的(x, y)有多少对. ...
- 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 ...
随机推荐
- CDQ分治模板
#include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #defi ...
- Python基础教程笔记——第5章:条件,循环和其他语句
5.1 print和import的更多信息 1. print()3.0之后print不再是语句,而是函数, >>> print('udg',12,13) udg 12 13 &g ...
- MITM Proxy环境搭建
MITM_Proxy环境搭建 环境要求 系统环境要求: Ubuntu 14.04 x64,CentOS 7 x64以上版本系统(建议使用xubuntu 14.04 x64,稳定硬件要求低) Pytho ...
- linux 安装报错:pkg-config not found
linux 安装报错:pkg-config not found 使用编译安装时,在执行./configure时报如下错误: ... ... checking for pkg-config... no ...
- SQL SERVER 2012 第四章 连接 JOIN の OUTER JOIN,完全连接FULL JOIN,交叉连接CROSS JOIN
SELECT <SELECT LIST> FROM <the table you want to be the "LEFT" table> <LEFT ...
- vm 安装CentOS7
1.首先需要到CentOS官网下载CentOS7的iso镜像文件,地址http://mirrors.cn99.com/centos/7/isos/x86_64/ 这里我选择的是迅雷种子文件 2.下载完 ...
- 如何使用shell收集linux系统状态,并把结果发给远端服务器
第一步:收集系统当天状态 load状态 内存状态 cpu状态 jvm相关信息:jstat jstack 网络信息 硬盘信息 第二步:发送到远端服务器 使用curl.wget.定义接口. https:/ ...
- IntelliJ IDEA14.0.3+Maven+SpringMVC+Spring+Hibernate光速构建Java权限管理系统(三)
注册登录 --利用简单的编写注册登录系统来打通从前端到后台的数据传输路径. 一.建立数据库.基本表 基本环境:mysql5,7.Navicat for MySQL11.0.9企业版. 我们在本地MyS ...
- Office WORD里插入图片,嵌入型只能显示一半怎么办
如下图所示,公式编辑器插入的图片如果用嵌入型只能显示一半,但是改成其他方式即可全部显示 选中有问题的段落,点击设置为单倍行距即可
- iOS开发--URL中汉字出现乱码
NSURL *nurl=[[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF ...