POJ 2480
可以容易得知,F=sum(p*phi(n/p))。思路就断在这里了。。。
看过别人的,才知道如下:
由于gcd(i,n*m)=gcd(i,m)*gcd(i,n),所以gcd为积性函数。而积性函数之和为积性函数。
所以F=sum(gcd(i,n))为积性函数。n=p1^k1*p2^k2....所以f(p1^k1)*f(p2^k2)...=F。
而f(p^r)由最初公式知f(p^r)=r*(p^r-p^(r-1))+p^r。代入以上公式即可求得。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std; int main(){
LL n;
while(scanf("%I64d",&n)!=EOF){
LL ans=1;
for(LL i=2;i*i<=n;i++){
LL r=0,p=1;
if(n%i==0){
while(n%i==0){
p*=i;
r++;
n/=i;
}
ans*=(r*(p-p/i)+p);
}
}
if(n>1){
ans*=(1*(n-1)+n);
}
printf("%I64d\n",ans);
}
return 0;
}
POJ 2480的更多相关文章
- POJ 2480 Longge's problem 积性函数
题目来源:id=2480" style="color:rgb(106,57,6); text-decoration:none">POJ 2480 Longge's ...
- poj 2480 Longge's problem 积性函数性质+欧拉函数
题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d ...
- POJ 2480 (约数+欧拉函数)
题目链接: http://poj.org/problem?id=2480 题目大意:求Σgcd(i,n). 解题思路: 如果i与n互质,gcd(i,n)=1,且总和=欧拉函数phi(n). 如果i与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 解题报告 (欧拉函数)
题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<al ...
- 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(欧拉函数)
题意 求$ \sum_{i=1}^n gcd(i,n) $ 给定 $n(1\le n\le 2^{32}) $. 链接 题解 欧拉函数 $φ(x)$ :1到x-1有几个和x互质的数. gcd(i,n) ...
- POJ 2480 求每一个数对于n的最大公约数的和
这里是枚举每一个最大公约数p,那么最后求的是f(n) = sigma(p*phi(n/p)) phi()为欧拉函数 这里可以试着算一下,然后会发现这个是积性函数的 那么只要考虑每一类质数分开算, ...
- POJ 2480 Longge's problem (积性函数,欧拉函数)
题意:求∑gcd(i,n),1<=i<=n思路:f(n)=∑gcd(i,n),1<=i<=n可以知道,其实f(n)=sum(p*φ(n/p)),其中p是n的因子.为什么呢?原因 ...
随机推荐
- cogs 1143. [石门中学2009] 切割树
1143. [石门中学2009] 切割树 ★ 输入文件:treecut.in 输出文件:treecut.out 简单对比时间限制:1 s 内存限制:128 MB treecut 题目描 ...
- oracle 有个xe版本
oracle 有个xe版本 学习了:http://blog.csdn.net/angiexia/article/details/8615771
- python3连接Mairadb数据库
<span style="font-size:18px;">#本代码演示的是python3.3.5下连接Mairadb数据库</span> <span ...
- UVA10370 Above Average
Above Average It is said that 90% of frosh expect to be above average in their class. You are to pro ...
- MFC 与Excel文件的交互操作
假日快要结束了.带着沉重的心情写下之前关于MFC与Excel文件交互的总结. 因为VS的版本号不同可能在操作上有些差异.所以在此指明下本篇文章的project环境为VS2013,也建议大家用最新的. ...
- jQuery取得循环列表的第一列值
有例如以下的表格: <table class="list_tab" id="personalDetail"> <tr class=" ...
- Android开发之大位图压缩水印处理
我们在发微博或者csdn博文的时候都能够给图片加上一个水印.一个独立的标识,那是怎么实现的呢?先封装一个BitmapTools封装类.该类要解决的问题是一将突破存储至sdcard中,二给图片加上水印. ...
- Cocos2d-x3.0 RenderTexture(三)
.h #include "cocos2d.h" #include "cocos-ext.h" #include "ui/CocosGUI.h" ...
- sdwebimage缓存图片
当使用SDWebImage时,如果用相同图片名的图片替换掉了原始缓存的图片,当再次请求的时候,还是使用的缓存图片,图片不会发生改变 原因:图片在NSCache中是以absolute url作为key存 ...
- BZOJ 4358 坑 莫队+线段树 死T
这是一个坑 竟然卡nsqrt(n)logn T死 等更 //By SiriusRen #include <cmath> #include <cstdio> #include & ...