题意

题目链接

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的问题(欧拉函数)的更多相关文章

  1. 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数

    题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...

  2. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

  3. Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1959  Solved: 1229[Submit][ ...

  4. [SDOI2012] Longge的问题 - 欧拉函数

    求 \(\sum\limits_{i=1}^{n}gcd(i,n)\) Solution 化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\) 筛出欧拉函数暴力求 ...

  5. bzoj 2705 [SDOI2012]Longge的问题——欧拉函数大水题

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2705 撕逼题.不就是枚举gcd==d,求和phi[ n/d ]么. 然后预处理sqrt (n ...

  6. poj 2480 Longge's problem [ 欧拉函数 ]

    传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2 ...

  7. 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 ...

  8. Bzoj-2705 Longge的问题 欧拉函数

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2705 题意: 求 sigma(gcd(i,n), 1<=i<=n<2^3 ...

  9. [SDOI2012]Longge的问题 欧拉反演_欧拉函数

    Code: #include<cstdio> #include<algorithm> #include<cmath> #include<string> ...

随机推荐

  1. Mac通过type-c接口无法识别移动硬盘

      最近买了一块移动硬盘以及硬盘盒连接到Mac上来使用,最近发现了一个问题,就是当我使用完后将硬盘推出第二天再次连接上的时候硬盘不能被识别了,连硬盘和上的数据指示灯也不会亮,但是连接的鼠标键盘却没问题 ...

  2. markdown上下左右,跳至行尾行首,重设快捷键

    概述 用markdown输入代码的时候觉得下面2件事非常不方便: (1)光标上下左右.(需要挪动手去按方向键) (2)光标跳至行尾和行首.(需要动手去按Home和End键) 为了简化,我特地更改了ST ...

  3. XStream进行xml和bean互转

    加入pom <dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId>x ...

  4. vue 自学笔记(6) axios的使用

    前情提要:axios 的使用 axios是一个ajax 的包,主要在node.js 使用 axios 的官网 https://www.kancloud.cn/yunye/axios/234845 一: ...

  5. win10 store 无法连接网络(原创)

    当你试过所有的解决攻略 都无效时,那么使用这个教程 关闭以下的蓝色框里的

  6. PowerShell 连接远程服务器

    >>服务端Enable-PSRemoting winrm quickconfig ————这个可能不需要 >>客户端Set-Item wsman:\localhost\Clie ...

  7. Linux命令yum和rpm

    yum命令使用 可以简化软件安装命令 yum可以做软件的 1自动安装,安装软件的时候会自动安装需要的依赖 yum install 软件名如安装epel源yum install epel-release ...

  8. Python 【web框架】之Flask

    flask 是Python实现的轻量级web框架.没有表单,orm等,但扩展性很好.很多Python web开发者十分喜欢.本篇介绍flask的简单使用及其扩展. 文中示例源码已经传到github:h ...

  9. linux下将指定目录加入环境变量的方法

    每个用户目录下都有一个对应的.bash_profile比如root用户对应/root/.bash_profile,普通用户cqh对应/home/cqh/.bash_profile,以root用户为例v ...

  10. 3分钟看完Java 8——史上最强Java 8新特性总结之第一篇 函数式编程基础

    目录 · 行为参数化 · Lambda表达式 · 概况 · 函数式接口 · 类型推断 · 使用外层变量 · 方法引用 · 复合Lambda表达式 行为参数化 1. 理解函数式编程要先理解行为参数化. ...