题意

题目链接

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. Eclipse 工作空间的相关说明

    工作空间文件说明 当eclipse选定一个文件夹作为workspace工作空间时,就会在该目录中生成一些文件. 共三个文件夹:.metadata ..recommenders .RemoteSyste ...

  2. Shell-18--正则表达式

    a*  a出现0或任意次,没有意义,会全输出

  3. iOS开发笔记(Swift)-针对Swift调用PPiFlatSegmentedControl项目的一些修改

    PPiFlatSegmentedControl项目是一个很流行的开源iOS控件库,提供了扁平化风格(Flat style)的SegmentedControl,可以自定义segment的颜色,图标.大小 ...

  4. Spark基础脚本入门实践1

    1.创建数据框架 Creating DataFrames val df = spark.read.json("file:///usr/local/spark/examples/src/mai ...

  5. django rest framework serializers解读

    serializers是什么?官网是这样的"Serializers allow complex data such as querysets and model instances to b ...

  6. 移动 Ubuntu16.04 桌面左侧的启动器到屏幕底部

    与其他 Linux 发行版不同,Ubuntu 多年来一直使用 Unity 做桌面环境,该环境的最突出特点就是桌面左侧有一个启动器栏(Launcher).从 16.04 版本开始,Ubuntu 提供了一 ...

  7. android 代码混淆示例

    参考其它资料为项目代码做了一下混淆 项目中使用了 slidingmenu   actionbarsherlock   fastjson  volley   httpclient 等第三方库, 并使用了 ...

  8. C#中List的方法RemoveAt小测试

    结论:在C#中将一个List中的项插入到别一个List中,会复制,而不是从源List中移除. 示例如下 void Start () { TestList (); } void TestList () ...

  9. SQL 必知必会·笔记<15>创建和操纵表

    创建表的两种办法: 使用DBMS 提供的交互式创建和管理数据库表的工具: 直接用SQL 语句创建. 表创建基础 创建表示例: CREATE TABLE Products ( prod_id ) NOT ...

  10. Java并发编程笔记之SimpleDateFormat源码分析

    SimpleDateFormat 是 Java 提供的一个格式化和解析日期的工具类,日常开发中应该经常会用到,但是由于它是线程不安全的,多线程公用一个 SimpleDateFormat 实例对日期进行 ...