【bzoj2705】[SDOI2012]Longge的问题 欧拉函数
题目描述
输入
输出
样例输入
6
样例输出
15
题解
欧拉函数
易得知满足gcd(n,x)==i的小于等于n的x的个数为phi(n/i),
并且欧拉函数可以在O(√n)的时间内快速求出。。
于是可以先求出所有n的因子,再用欧拉函数得出答案。
由于因子是成对出现的,所以因子并不需要枚举到n,只需枚举到√n。如果i是n的因子,那么n/i也是n的因子,注意此时i*i==n不能算进答案内。
#include <cstdio>
typedef long long ll;
ll phi(ll x)
{
ll ans = x , t = x , i;
for(i = 2 ; i * i <= x ; i ++ )
{
if(t % i == 0) ans = ans * (i - 1) / i;
while(t % i == 0) t /= i;
}
if(t > 1) ans = ans * (t - 1) / t;
return ans;
}
int main()
{
ll n , i , ans = 0;
scanf("%lld" , &n);
for(i = 1 ; i * i <= n ; i ++ )
{
if(n % i == 0)
{
ans += i * phi(n / i);
if(i * i < n) ans += (n / i) * phi(i);
}
}
printf("%lld\n" , ans);
return 0;
}
【bzoj2705】[SDOI2012]Longge的问题 欧拉函数的更多相关文章
- BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)
题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...
- 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> ...
随机推荐
- sql sever 基础 练习题
--1. 求半径2米,高3米的圆柱体体积. declare r @hight float,@r float,@ratio float ,@ v float --声明变量 set @hight=3 -- ...
- javaScript 字符串与unicode码之间的相互转换,函数的封装
在我们的开发过程中,有时在对数据进行储存的时候,我们需要将字符串转成unicode. 比如,在jsp开发时,前端使用页面间传值时,将传值参数先存入cookie中,然后在使用的时候,再从ookie中取出 ...
- centos下安装docker以及docker-composer
背景 docker已经出来了很久,而我一直想混迹到docker大军中进行冲锋陷阵,恰逢公司项目的需要,因此今天玩了一把docker的安装.使用Docker 一键部署 LNMP+Redis 环境 事先准 ...
- Array-快餐管饱
一.如何获得一个数组? rsp: 1. [] 2.new Array() 3.str.split() ps:new Array()可以不加括号,其传一个参数代表数组长度,两个及以上就是初始化数组. ...
- 2.从print到自省
print是一个函数 为什么print是一个函数呢?可以在交互式解释器下 输入: >>> type(print) 输出: <class 'builtin_function_ ...
- 网站mysql防止sql注入攻击 3种方法总结
mysql数据库一直以来都遭受到sql注入攻击的影响,很多网站,包括目前的PC端以及手机端都在使用php+mysql数据库这种架构,大多数网站受到的攻击都是与sql注入攻击有关,那么mysql数据库如 ...
- 常用数字信号的产生(C实现)-ARMA模型数据生成
ARMA模型属于信号现代谱估计的范畴,AR模型常用于信号的线性预测.AR模型最后归结为线性方程,MA最后为非线性方程,因此,AR模型使用较多. AR模型最后归结为解Yule-Walker方程,对应矩阵 ...
- C# 生成机器码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 【动态规划】[UVA1025]A Spy in the Metro 城市里的间谍
参考:https://blog.csdn.net/NOIAu/article/details/71517440 https://blog.csdn.net/c20180630/article/deta ...
- Mac系统下安装Homebrew后无法使用brew命令,-bash: brew: command not found
使用如下命令: sudo vim .bash_profile 然后输入以下代码: export PATH=/usr/local/bin:$PATH 再使用以下命令使配置生效: source .bash ...