【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> ...
随机推荐
- thinkphp发送邮箱(以thinkphp5作为示例)。
第一步:设置我们的邮箱客户端授权码 第二步:下载相应的第三方类库(我这里用的PHPemail) 这是phpemailde 第三方类库的文件下载地址:https://github.com/PHPMail ...
- jquery easyui alert闪一下的问题
最近做项目使用了 jQuery EasyUI,版本是 1.4.3.x,在使用alert方法的时候如果alert后面执行页面跳转的话alert的消息只会闪一下,就跳到其他页面了 $.messager.a ...
- Hadoop(22)-Hadoop数据压缩
1.压缩概述 2.压缩策略和原则 3.MapReduce支持的压缩编码 64位系统下的单核i7,Snappy的压缩速率可以达到至少250MB/S,解压缩速率可以达到至少500MB/S 4.压缩方式选择 ...
- scrapy框架爬取笔趣阁
笔趣阁是很好爬的网站了,这里简单爬取了全部小说链接和每本的全部章节链接,还想爬取章节内容在biquge.py里在加一个爬取循环,在pipelines.py添加保存函数即可 1 创建一个scrapy项目 ...
- C语言实例解析精粹学习笔记——33(扑克牌的结构表示)
实例33: 使用“结构”定义一副扑克牌,并对变量赋值,输出结果 思路: 扑克牌有4种花色,用枚举类型表示花色,其他都是结构体的简单应用 程序代码: #include <stdio.h> # ...
- UVA 1593 Alignment of Code(紫书习题5-1 字符串流)
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...
- python2.7练习小例子(九)
9)1.题目:暂停一秒输出. 程序分析:使用 time 模块的 sleep() 函数. 程序源代码: #!/usr/bin/python # -*- coding: UTF-8 ...
- flask与javascript及ajax
flask与javascript及ajax 1. flask+js 1.1. 最简单的 最简单的元素信息改变. {% block content %} <h1>我的第一张网 ...
- json 处理日期格式
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") private Date createT ...
- Qt irrlicht(鬼火)3D引擎 摄像机旋转问题
点击打开链接Irrlicht中的摄像有一个函数 setUpVector() if (m_device != 0 ) { core::vector3df rotation(y,x,0.f); m_cam ...