POJ2480 Longge's problem
题意
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10642 | Accepted: 3563 |
Description
"Oh, I know, I know!" Longge shouts! But do you know? Please solve it.
Input
A number N per line.
Output
Sample Input
2
6
Sample Output
3
15
Source
分析
=\sum_{d|n}d*\sum_{i=1}^{\frac nd}[\gcd(i,\frac nd)=1]=\sum_{d|n}d*\varphi(\frac nd) \\
=\sum_{d|n}d*\frac nd *\prod_{i=1,p_i|\frac nd}^m(1-\frac 1p_i)
\]
那么直接把\(n\)质因数分解就行了。时间复杂度\(O(\sqrt{n})\)
#include<iostream>
typedef long long ll;
int main(){
ll n;
while(~scanf("%lld",&n)){
ll ans=n;
for(ll i=2,cnt;i*i<=n;++i)if(n%i==0){
cnt=0;
while(n%i==0) n/=i,++cnt;
ans=ans/i*((i-1)*cnt+i);
}
if(n>1) ans=ans/n*((n-1)+n);
printf("%lld\n",ans);
}
return 0;
}
POJ2480 Longge's problem的更多相关文章
- poj2480——Longge's problem(欧拉函数)
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9190 Accepted: 3073 ...
- POJ2480 Longge's problem gcd&&phi
题意简洁明了.做这题主要是温习一下phi的求法.令gcd(i,n)=k,实际上我们只需要求出有多少个i使得gcd(i,n)=k就可以了,然后就转化成了求phi(n/k)的和,但是n很大,我们不可能预处 ...
- POJ2480:Longge's problem(欧拉函数的应用)
题目链接:传送门 题目需求: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N ...
- Longge's problem poj2480 欧拉函数,gcd
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6918 Accepted: 2234 ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
- 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 ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- Longge's problem
Longge's problem 求\(\sum_{i=1}^ngcd(i,n)\),\(n< 2^{31}\). 解 理解1: 注意式子的实际意义,显然答案只可能在n的约数中,而现在问题变成了 ...
- Longge's problem(欧拉函数应用)
Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...
随机推荐
- 【原创】QString 函数 replace()indexOf()、 lastindexOf()
1.替换函数 示例: QString x = "Say yes!"; QString y = "no"; x.replace(, , y); // x == & ...
- 《Python》并发编程
手工操作 —— 穿孔卡片 1946年第一台计算机诞生--20世纪50年代中期,计算机工作还在采用手工操作方式.此时还没有操作系统的概念. 程序员将对应于程序和数据的已穿孔的纸带(或卡片)装入输 ...
- Innodb引擎简介
一.锁 二.什么情况出现阻塞 1.频繁更改的表,出现了慢查询 2.频繁访问的表,出现了备份等(表级锁) 三.查看运行情况 show engine innodb status; 四.关键参数 innod ...
- UUID+随机数
import java.util.Random; import java.util.UUID; public class UUIDUtils { public static String getUUI ...
- js 循环遍历数组
var a =[1,3,4]; a.each(functiom{ .... }) or for (var x in a ){ .... }
- ubantu安装python3虚拟环境
Ubuntu安装python3虚拟环境 安装虚拟环境 步骤: 打开Linux终端(快捷键Ctrl+Alt+T),输入命令: sudo apt install python-virtualenv sud ...
- 【Python】数字驱动
#练习1:打开3个网址,每个等3秒钟 urls.txt: http://www.baidu.com http://www.sogou.com http://www.sohu.com main.py: ...
- zookeeper和dubbo中出现的问题
报错出现timeout关键字 解决:在服务发布时,添加timeout字段 <!-- 5.服务发布 --> <dubbo:service interface="com.sxt ...
- ubuntu ssh 与 Samba安装
ssh 安装:sudo apt-get install openssh-server 确认sshserver是否启动:ps -aux | grep ssh(/etc/init.d/ssh start, ...
- triplet改进,变种
1.一开始是FaceNet 2.一个重要的改进:image-based, Ding etal. 3.对于样本挑选的改进: 1)hard samples: hard positive 和hard neg ...