[bzoj]2705: [SDOI2012]Longge的问题[数论][数学][欧拉函数][gcd]
Longge的问题
Description
Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题。现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N)。
Input
一个整数,为N。
Output
一个整数,为所求的答案。
Sample Input
6
Sample Output
15
HINT
【数据范围】
对于60%的数据,0<N<=2^16。
对于100%的数据,0<N<=2^32。
注意到这些最大公约数肯定是n的约数,对于约数K,我们想找出gcd(n,i)=k的有多少个,也即gcd(n/k,i/k)=1,也就等价于求φ(n/k)。
ans=Σφ(n/k)*k
问题就在于怎么求φ(n),之前竟然一直不知道可以sqrt(n)计算,感觉自己好傻,今天学习了...(一直以为要用递推,不然就要写线性筛[神经病啊])
还有就是枚举sqrt(n)时注意k*k=n的情况,没判这种情况结果bzoj过了,luogu没过...很尴尬。
代码:
//2017.10.31
//math
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll ;
inline ll read();
namespace lys{
ll n,ans;
ll phi(ll x){
int i;
ll w=x,res=x;
;1LL*i*i<=w;i++){
if(!(x%i)){
res=res*(i-)/i;
while(!(x%i)) x/=i;
}
}
) res=res*(x-)/x;
return res ;
}
int main(){
int i;
n=read();
;1LL*i*i<=n;i++)
if(!(n%i)){
ans+=phi(n/i)*i;
if(1LL*i*i!=n) ans+=phi(i)*(n/i);
}
printf("%lld\n",ans);
;
}
}
int main(){
lys::main();
;
}
inline ll read(){
ll kk=,ff=;
char c=getchar();
'){
;
c=getchar();
}
+c-',c=getchar();
return kk*ff;
}
[bzoj]2705: [SDOI2012]Longge的问题[数论][数学][欧拉函数][gcd]的更多相关文章
- BZOJ.2705.[SDOI2012]Longge的问题(莫比乌斯反演 欧拉函数)
题目链接 \(Description\) 求\[\sum_{i=1}^n\gcd(i,n)\] \(Solution\) \[ \begin{aligned} \sum_{i=1}^n\gcd(i,n ...
- BZOJ 2705: [SDOI2012]Longge的问题( 数论 )
T了一版....是因为我找质因数的姿势不对... 考虑n的每个因数对答案的贡献. 答案就是 ∑ d * phi(n / d) (d | n) 直接枚举n的因数然后求phi就行了. 但是我们可以做的更好 ...
- [bzoj 2705][SDOI2012]Longge的问题(数学)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2705 分析: 设k为n的因数 设f[k]为gcd(x,n)==k的x的个数,容易知道a ...
- hiho一下 第九十六周 数论五·欧拉函数
题目1 : 数论五·欧拉函数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho有时候会用密码写信来互相联系,他们用了一个很大的数当做密钥.小Hi和小Ho约定 ...
- hdu 1286:找新朋友(数论,欧拉函数)
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hihoCoder 数论五·欧拉函数
题目1 : 数论五·欧拉函数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho有时候会用密码写信来互相联系,他们用了一个很大的数当做密钥.小Hi和小Ho约定 ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
- 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: 2554 Solved: 1566[Submit][ ...
随机推荐
- 应用安全 - 工具 - 知道创宇 - CEYE检测平台
DNS Query
- [转帖]PostgreSQL ident和peer基于操作系统用户的认证
PostgreSQL ident和peer基于操作系统用户的认证 https://yq.aliyun.com/articles/55898 其实 local和127. 还是有区别的 这里面应该就是对应 ...
- BindWeb - Bind智能DNS管理系统介绍
2019-05-08 演示网站: https://bindw.cdneks.com demo/demo 2018-11-27 修改部署架构,取消网络共享存储设备,在每台BIND服务器启用NFS4并仅向 ...
- 部署CM集群首次运行报错:Formatting the name directories of the current NameNode.
1. 报错提示 Formatting the name directories of the current NameNode. If the name directories are not emp ...
- How to attach multiple files in the Send Mail Task in SSIS
Let’s say you need to create a SSIS package that creates 2 files and emails the files to someone. Yo ...
- CAS单点登录系统--进阶
2.CAS服务端数据源设置 2.1需求分析 我们现在让用户名密码从我们的优乐选的user表里做验证 2.2配置数据源 (1)修改cas服务端中web-inf下deployerConfigContext ...
- java基础笔记(3)
捕获异常: try{ ...... }catch(Exception e){ ...... }finally{ ...... } 注意:在写多重catch时需先小后大: 自定义异常: String字符 ...
- 偶遇com组件 .rc 文件 not found .tlb文件问题:
好久木有弄com组件来,记忆已经模糊了,今天遇见一个编译问题,折腾了半天,mark一下: xxx_x64.rc(273): error RC2135: file not found: xxx.tlb ...
- PHP数据结构基本概念
原文:https://www.cnblogs.com/crystaltu/p/6408484.html 学习任何一种技术都应该先清楚它的基本概念,这是学习任何知识的起点!本文是讲述数据结构的基本概念, ...
- NoSQL特点