求 \(\sum\limits_{i=1}^{n}gcd(i,n)\)

Solution

化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\)

筛出欧拉函数暴力求答案即可

#include <bits/stdc++.h>
using namespace std;
#define int long long
int phi(int n) {
int m = floor(sqrt(n + 0.5)), ans = n;
for (int i = 2; i <= m; i++) {
if (n % i == 0) {
ans = ans / i * (i - 1);
while (n % i == 0) n /= i;
}
}
if (n != 1) ans = ans / n * (n - 1);
return ans;
}
signed main() {
int n,ans=0;
cin>>n;
int lim=sqrt(n);
for(int i=1;i<=lim;i++) if(n%i==0) {
ans+=i*phi(n/i)+(i!=n/i)*n/i*phi(i);
}
cout<<ans;
}

[SDOI2012] Longge的问题 - 欧拉函数的更多相关文章

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

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

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

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

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

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

  4. BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)

    题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...

  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. [SDOI2012]Longge的问题 欧拉反演_欧拉函数

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

  9. poj 2480 Longge's problem 欧拉函数+素数打表

    Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathem ...

随机推荐

  1. 「Flink」理解流式处理重要概念

    什么是流式处理呢? 这个问题其实我们大部分时候是没有考虑过的,大多数,我们是把流式处理和实时计算放在一起来说的.我们先来了解下,什么是数据流. 数据流(事件流) 数据流是无边界数据集的抽象 我们之前接 ...

  2. Dijkstra算法2

    // 再来一手精髓的Dijkstra // 复杂度O( E*log(V) ) #include <cstdio> #include <iostream> #include &l ...

  3. C#实现把String字符串转化为SQL语句中的In后接的参数

    实现把String字符串转化为In后可用参数代码: public string StringToList(string aa) { string bb1 = "("; if (!s ...

  4. Html介绍,了解html代码的注释

    什么是代码注释?在代码编辑器中的注释代码是不会在浏览器窗口展示的!html代码注释的作用是帮助程序员标注代码的用途,过一段时间后再看你之前编写的代码,很快可以想起这个代码的用途.代码注释不仅方便程序员 ...

  5. P5840 [COCI2015]Divljak

    // powered by c++11 // by Isaunoya #include <bits/stdc++.h> #define rep(i, x, y) for (register ...

  6. ajax 携带参数传递 页面 查找

    不从新定义只能传过来数字  ,不能穿字符串 完整的ajax 获取参数跳转页面

  7. MongoDB 添加用户名和密码

    MongoDB 添加用户名和密码 我用的是 mongodb3.6,如果没有的话先安装. sudo apt install mongodb 终端输入mongo,首先添加管理用户, show dbs // ...

  8. python3的bytes数据类型

    python已升级到了3.0,都说现在是属于python3,未来也是属于python3,那python3到底改了些什么呢? 其中我记得非常清楚的是,python3对文本和二进制数据作了更为清晰的区分. ...

  9. 初识Socket通讯编程(一)

    一.什么是socket? 当两台计算机需要通信的时候,往往我们使用的都是TCP去实现的,但是并不会直接去操作TCP协议,通常是通过Socket进行tcp通信.Socket是操作系统提供给开发者的一个接 ...

  10. MS SQL为字段添加说明

    以ms sql server 14  v17为例. 如下表dbo.Q中有一个字段'' 首先在数据库的系统存储过程列表中: 找到sys.sp_addextendedproperty,使用这个为字段添加一 ...