Luogu P1447 [NOI2010]能量采集 数论??欧拉
刚学的欧拉反演(在最后)就用上了,挺好$qwq$
题意:求$\sum_{i=1}^{N}\sum_{j=1}^{M}(2*gcd(i,j)-1)$
原式
$=2*\sum_{i=1}^{N}\sum_{j=1}^{M}gcd(i,j)\space-m*n$
$=2*\sum_{i=1}^{N}\sum_{j=1}^M\sum_{d|gcd(i,j)}\varphi(d)\space-m*n$
$=2*\sum_{i=1}^{\lfloor \frac{N}{d}\rfloor}\sum_{j=1}^{\lfloor \frac{M}{d} \rfloor}\sum_{d=1}^N\varphi(d)\space-m*n$
$=2*\sum_{d=1}^N\varphi(d)\lfloor \frac{N}{d}\rfloor \lfloor \frac{M}{d} \rfloor \space-m*n$
所以又可以整除分块+线性筛$\varphi(n)$前缀和$
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define R register int
using namespace std;
namespace Fread {
static char B[<<],*S=B,*D=B;
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
}using Fread::g;
const int N=;
ll p[N],pri[N],cnt;
bool v[N];
inline void PHI(int n) { p[]=;
for(R i=;i<=n;++i) {
if(!v[i]) pri[++cnt]=i,p[i]=i-;
for(R j=;j<=cnt&&i*pri[j]<=n;++j) {
v[i*pri[j]]=true;
if(i%pri[j]==) {
p[i*pri[j]]=pri[j]*p[i];
break;
} p[i*pri[j]]=p[i]*p[pri[j]];
}
} for(R i=;i<=n;++i) p[i]+=p[i-];
} int n,m;
ll ans;
signed main() {
#ifdef JACK
freopen("NOIPAK++.in","r",stdin);
#endif
PHI(); n=g(),m=g(); n>m?swap(n,m):void();
for(R l=,r;l<=n;l=r+) {
r=min(n/(n/l),m/(m/l));
ans+=(ll)*(p[r]-p[l-])*(n/l)*(m/l);
} printf("%lld\n",ans-(ll)n*m);
}
2019.06.09
Luogu P1447 [NOI2010]能量采集 数论??欧拉的更多相关文章
- bzoj 2005: [Noi2010]能量采集 筛法||欧拉||莫比乌斯
2005: [Noi2010]能量采集 Time Limit: 10 Sec Memory Limit: 552 MB[Submit][Status][Discuss] Description 栋栋 ...
- luogu P1447 [NOI2010]能量采集 欧拉反演
题面 题目要我们求的东西可以化为: \[\sum_{i=1}^{n}\sum_{j=1}^{m}2*gcd(i,j)-1\] \[-nm+2\sum_{i=1}^{n}\sum_{j=1}^{m}gc ...
- Luogu P1447 [NOI2010]能量采集
Preface 最近反演题做多了看什么都想反演.这道题由于数据弱,解法多种多样,这里简单分析一下. 首先转化下题目就是对于一个点\((x,y)\),所消耗的能量就是\(2(\gcd(x,y)-1)+1 ...
- 【BZOJ】2005: [Noi2010]能量采集(欧拉函数+分块)
http://www.lydsy.com/JudgeOnline/problem.php?id=2005 首先和某题一样应该一样可以看出每个点所在的线上有gcd(x,y)-1个点挡着了自己... 那么 ...
- BZOJ2005: [Noi2010]能量采集(欧拉函数)
Description 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后, 栋栋再使用一个能量汇集机器把这些植物采集到的能量汇集到一起. 栋栋的植物种 ...
- BZOJ 2005: [Noi2010]能量采集( 数论 + 容斥原理 )
一个点(x, y)的能量损失为 (gcd(x, y) - 1) * 2 + 1 = gcd(x, y) * 2 - 1. 设g(i)为 gcd(x, y) = i ( 1 <= x <= ...
- 洛谷P1447 - [NOI2010]能量采集
Portal Description 给出\(n,m(n,m\leq10^5),\)计算\[ \sum_{i=1}^n \sum_{j=1}^m (2gcd(i,j)-1)\] Solution 简单 ...
- P1447 [NOI2010]能量采集
题目描述 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后,栋栋再使用一个能量汇集机器把这些植物采集到的能量汇集到一起. 栋栋的植物种得非常整齐,一共 ...
- 洛谷 P1447 [NOI2010]能量采集 (莫比乌斯反演)
题意:问题可以转化成求$\sum_{i=1}^{n}\sum_{j=1}^{m}(2*gcd(i,j)-1)$ 将2和-1提出来可以得到:$2*\sum_{i=1}^{n}\sum_{j=1}^{m} ...
随机推荐
- Python 使用正则表达式验证密码必须包含大小写字母和数字
校验密码是否合法的程序. 输入一个密码 1.长度5-10位 2.密码里面必须包含,大写字母.小写字母和数字 3.最多输入5次 ===================================== ...
- jQuery 获取有多个class名的元素
HTML内容: <div class="write-upload"> <p class="write-files old-files"> ...
- 重新拾取:ASP.NET Core WebApi 使用Swagger支持授权认证
园子里已经有很多.NET Core 集成Swagger的文章,但对于使用授权的介绍蛮少的. public static class SwaggerServiceExtensions { public ...
- PyNLPIR python中文分词工具
官网:https://pynlpir.readthedocs.io/en/latest/ github:https://github.com/tsroten/pynlpir NLP ...
- ZOJ1905Power Strings (KMP||后缀数组+RMQ求循环节)
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- 「USACO08DEC」「LuoguP2922」秘密消息Secret Message(AC自动机
题目描述 Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret bin ...
- python使用uuid生成唯一id或str
介绍: UUID是128位的全局唯一标识符,通常由32字节的字符串表示. 使用: import uuid print uuid.uuid1() 14bfe806-f1c7-11e6-83b5-0680 ...
- 如何为现有控件的DependencyProperty添加Value Changed事件?
主要是利用DependencyPropertyDescriptor 的AddValueChanged 方法, 比如下面的例子为DataGridColumn的VisibilityPr ...
- makefile 使用【转载】
该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神博客: http://blog.csdn.net/haoel/article/details/2886 makefile很重 ...
- win7 64位搭建Mantis 缺陷管理系统
什么是Mantis MantisBT is a free popular web-based bugtracking system (feature list). It is written in t ...