前言:还算比较简单的数学题,我这种数学蒟蒻也会做QAQ。

---------------

题意:求$\sum\limits_{i=1}^n gcd(i,n)$的值。

设$gcd(i,n)=d$,即$d$为$i$和$n$的因数,那么有$gcd(i/d,n/d)=1$。假设我们求出了$x$个满足条件的$i$,那么总的结果就是$x*d$。我们因此可以枚举$n$的因数,累加即可。注意判断$n$是不是完全平方数。

问题来了:怎么求满足$gcd(i/d,n/d)=1$的$i$的个数?欧拉函数啊!我们可以$\sqrt n$地求出$φ(n/i)$,结果就是$φ(n/i)*d$。

注:欧拉函数的通式为$φ(x)=x*\prod\limits_{i=1}^n (1-\frac{1}{p_i})$ ($p_i$为$x$的质因数)

代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans;
int phi(int x)
{
int res=x;
for (int i=;i*i<=x;i++)
{
if (x%i==)
{
res=res*(i-)/i;
while(x%i==) x/=i;
}
}
if (x>) res=res*(x-)/x;
return res;
}
signed main()
{
scanf("%lld",&n);
int sq=sqrt(n);
for (int i=;i<=sq;i++)
{
if (n%i==)
{
ans+=phi(n/i)*i;
if (i*i!=n) ans+=phi(i)*(n/i);
}
}
cout<<ans;
return ;
}

【SDOI2012】Longge 的问题 题解(欧拉函数)的更多相关文章

  1. 由 [SDOI2012]Longge的问题 探讨欧拉函数和莫比乌斯函数的一些性质和关联

    本题题解 题目传送门:https://www.luogu.org/problem/P2303 给定一个整数\(n\),求 \[ \sum_{i=1}^n \gcd(n,i) \] 蒟蒻随便yy了一下搞 ...

  2. BZOJ2705 SDOI2012 Longge的问题 【欧拉函数】

    BZOJ2705 SDOI2012 Longge的问题 Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, ...

  3. BZOJ 2705 [SDOI2012]Longge的问题(欧拉函数)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2705 [题目大意] 求出∑gcd(i,N)(1<=i<=N) [题解] $ ...

  4. 【洛谷 P2303】 [SDOi2012]Longge的问题 (欧拉函数)

    题目链接 题意:求\(\sum_{i=1}^{n}\gcd(i,n)\) 首先可以肯定,\(\gcd(i,n)|n\). 所以设\(t(x)\)表示\(gcd(i,n)=x\)的\(i\)的个数. 那 ...

  5. 【POJ 2480】Longge's problem(欧拉函数)

    题意 求$ \sum_{i=1}^n gcd(i,n) $ 给定 $n(1\le n\le 2^{32}) $. 链接 题解 欧拉函数 $φ(x)$ :1到x-1有几个和x互质的数. gcd(i,n) ...

  6. 题解报告:poj 2480 Longge's problem(欧拉函数)

    Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...

  7. Longge's problem poj2480 欧拉函数,gcd

    Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6918   Accepted: 2234 ...

  8. Longge's problem(欧拉函数应用)

    Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...

  9. POJ2480:Longge's problem(欧拉函数的应用)

    题目链接:传送门 题目需求: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N ...

  10. poj2480——Longge's problem(欧拉函数)

    Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9190   Accepted: 3073 ...

随机推荐

  1. 解决nginx 出现 413:Request Entity Too Large

    去网上搜了一下,说是上传文件大小超过nginx的限制大小(nginx据说默认只能上传不超过2MB的文件) 解决方法: #nginx/conf/nginx.conf http { ... client_ ...

  2. 一小时完成后台开发:DjangoRestFramework开发实践

    DjangoRestFramework开发实践 在这之前我写过一篇关于Django与Drf快速开发实践的博客,Django快速开发实践:Drf框架和xadmin配置指北,粗略说了一下Drf配置和基本使 ...

  3. Mysql 实例:mysql语句练习50题(sqlalchmy写法)

    为了练习sql语句,在网上找了一些题,自己做了一遍,收益颇多.很多地方换一种思路,有更好的写法,欢迎指正. 题目地址:https://blog.csdn.net/fashion2014/article ...

  4. 数据可视化之 图表篇(五) PowerBI图表不够炫酷?来看看这个

    现在这个大数据时代,每时每刻.各行各业都在产生多种多样的海量数据,如何简单高效的来理解.挖掘这些数据,发现背后的见解就非常重要. 本文介绍这个图表就可以帮你快速发现海量数据背后的见解,微软研究院打造的 ...

  5. redis(八):Redis 哈希(Hash)

    Redis 哈希(Hash) Redis hash 是一个 string 类型的 field 和 value 的映射表,hash 特别适合用于存储对象. Redis 中每个 hash 可以存储 232 ...

  6. Django之Model、Form、ModelForm区别

    本节内容: 1:Model               https://www.cnblogs.com/shuai1991/p/10844662.html 2:Form                 ...

  7. 纯 CSS 实现滑动轮播图效果

    只使用css实现轮播图简单的操作 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  8. Apache Kylin v3.1.0 重点功能推介

    Apache Kylin v3.1.0 已于上周正式发布,其中包含了许多值得一试的新功能,本文选择了 Presto 查询下压引擎.Flink 构建引擎.Kylin on Kubernetes 解决方案 ...

  9. OSCP Learning Notes - Capstone(4)

    SickOS 1.2 Walkthrough Preparation: Down load the SickOS virtual machines from the following website ...

  10. OSCP Learning Notes - Post Exploitation(4)

    Pivoting 1. Edit the virtual network settings of the Vmware. 2. Set the Network Adapter(s) of Kali L ...