BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)
题意
Sol
开始用反演推发现不会求\(\mu(k)\)慌的一批
退了两步发现只要求个欧拉函数就行了
\(ans = \sum_{d | n} d \phi(\frac{n}{d})\)
理论上来说复杂度是\(O(n)\)的,但是\(d\)的值十分有限。在\(2^{32}\)内最多的约数也只有1920个。
/*
*/
#include<bits/stdc++.h>
#define LL long long
#define int long long
const int MAXN = 1e5 + 10, INF = 1e9 + 7;
using namespace std;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N;
int calc(int N) {
int res = 1;
for(int i = 2; i * i <= N; i++) {
if(N % i == 0) {
int now = (i - 1); N /= i;
while(N % i == 0) now *= i, N /= i;
res *= now;
}
}
if(N != 1) res *= (N - 1);
return res;
}
signed main() {
N = read();
int ans = 0;
for(int i = 1; i * i <= N; i++) {
if(N % i == 0) {
ans += i * calc(N / i);
if(i != N / i) ans += (N / i) * calc(i);
}
}
cout << ans;
return 0;
}
/*
3 7
a*b
aebr*ob
*/
BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)的更多相关文章
- 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数
题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
- [SDOI2012] Longge的问题 - 欧拉函数
求 \(\sum\limits_{i=1}^{n}gcd(i,n)\) Solution 化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\) 筛出欧拉函数暴力求 ...
- bzoj 2705 [SDOI2012]Longge的问题——欧拉函数大水题
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2705 撕逼题.不就是枚举gcd==d,求和phi[ n/d ]么. 然后预处理sqrt (n ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6383 Accepted: 2043 ...
- Bzoj-2705 Longge的问题 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2705 题意: 求 sigma(gcd(i,n), 1<=i<=n<2^3 ...
- [SDOI2012]Longge的问题 欧拉反演_欧拉函数
Code: #include<cstdio> #include<algorithm> #include<cmath> #include<string> ...
随机推荐
- DevExpress--TreeList节点添加图片
这个过程相对来说比较简单,网上也有不少资料,但是自己在做过之后为了记住,算是给自己写一个博客吧. 下面直接上具体的流程 1.前提 控件使用的都是DevExpress和winform的原生控件两种: 2 ...
- 项目Alpha冲刺(团队4/10)
项目Alpha冲刺(团队4/10) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标: 完成项目Alpha版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 ...
- electron 使用 node-ffi 调用 C++ 动态链接库(DLL)
一.为什么需要使用DLL 需要使用系统 API 操作或扩展应用程序: 需要调用第三方的接口API,特别是与硬件设备进行通信,而这些接口 API 基本上都是通过 C++ 动态链接库(DLL)实现的: 需 ...
- JavaScript对象编程-第3章
目录 Date对象 Math对象 数组对象 字符串对象 正则表达式对象 什么是对象 对象拥有属性和方法,属性各种数据类型,方法对属性中的数据进行操作. JavaScript的对象 内置对象 Date. ...
- Keras 资源
Keras中文文档 github Keras example 官方博客 A ten-minute introduction to sequence-to-sequence learning in Ke ...
- 你(可能)不知道的web api
你(可能)不知道的web api 简介 作为前端er,我们的工作与web是分不开的,随着HTML5的日益壮大,浏览器自带的webapi也随着增多.本篇文章主要选取了几个有趣且有用的webapi进行介绍 ...
- C# TableLayoutPanel使用方法
一.利用TableLayoutPanel类展示表格,以10行5列为例 第1步:在前台创建一个panel,使TableLayoutPanel对象填充其内部. 第2步:创建TableLayoutPanel ...
- vue 父子组件之间传参
父组件中有子组件 msg 为父组件向子组件传的内容, 子组件向父组件传参数 子组件:this.$emit("shownumber",[this.num]);//this.$emi ...
- 对nginx中location的认识
关于一些对location认识的误区 1.location的匹配顺序是“先匹配正则,在匹配普通”. location的匹配顺序其实是“先匹配普通,在匹配正则”.造成误解的原因是:正则匹配会覆盖普通匹配 ...
- xlwt set style making error: More than 4094 XFs (styles)
使用Xlwt,当内容过多时,会报错:More than 4094 XFs (styles) 解决方法: wb = xlwt.Workbook(style_compression=2) 使用style_ ...