/**
大意: 计算f(n) = ∑ gcd(i, N) 1<=i <=N.
思路: gcd(i,x*y) = gcd(i,x) * gcd(i, y ) 所以gcd 为积性函数
又因为积性函数的和函数 也是积性函数(具体数学,了解即可)
f(n) = f(p1^a1 * p2^a2 * p3^a3*......* pn^an )
= f(p1^a1) * f(p2^a2) * f(p3* a3) ......
现在我们先单独考虑一个 f(p1^a1)
f(p^k)=1*φ(p^k)+ p*φ[p^(k-1)]+p^2*φ[p^(k-2)]+…+ p^(k-1)*φ[p]+ p^k*φ[1]②
由欧拉函数性质知:φ(p^k)=(p-1)*p^(k-1)① 将①代入②得到:
f(p^k)= 1*φ(p^k) + p*φ[p^(k-1)] + p^2*φ[p^(k-2)] +…+ p^(k-1)*φ[p] + p^k*φ[1]
=1*(p-1)*p^(k-1)+p*(p-1)*p^(k-2)+ p^2*(p-1)*p^(k-3)+…+p^(k-1)*(p-1)+p^k (这要注意φ[1]=1不能代入①式求解)
=(p-1)*p^(k-1)+ (p-1)*p^(k-1)+(p-1)*p^(k-1)+…+(p-1)*p^(k-1)+ p^k
=k*(p-1)*p^(k-1)+ p^k
**/
#include <iostream> using namespace std; int main()
{
long long n;
while(cin>>n){
long long ans =;
for(long long i=;i*i<=n;i++){
long long tmp =;
long long cnt =;
while(n%i==){
tmp *=i;
cnt++;
n = n/i;
}
ans *= (cnt*(i-)*tmp/i + tmp);
}
if(n>){
ans *= *n-;
}
cout<<ans<<endl;
}
return ;
}

poj 2480 Longge's problem的更多相关文章

  1. poj 2480 Longge's problem [ 欧拉函数 ]

    传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2 ...

  2. poj 2480 Longge's problem 欧拉函数+素数打表

    Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathem ...

  3. 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 ...

  4. [poj 2480] Longge's problem 解题报告 (欧拉函数)

    题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<al ...

  5. 题解报告:poj 2480 Longge's problem(欧拉函数)

    Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...

  6. 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的因子.为什么呢?原因 ...

  7. poj 2480 Longge's problem 积性函数

    思路:首先给出几个结论: 1.gcd(a,b)是积性函数: 2.积性函数的和仍然是积性函数: 3.phi(a^b)=a^b-a^(b-1); 记 f(n)=∑gcd(i,n),n=p1^e1*p2^e ...

  8. POJ 2480 Longge&#39;s problem 积性函数

    题目来源:id=2480" style="color:rgb(106,57,6); text-decoration:none">POJ 2480 Longge's ...

  9. poj 2480 Longge&#39;s problem 积性函数性质+欧拉函数

    题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d ...

随机推荐

  1. Is it possible to implement a Firebug-like “inspect element” DOM element highlighter with client-side JavaScript?

    Is it possible to implement a Firebug-like "inspect element" DOM element highlighter with ...

  2. PHP下通过file_get_contents\curl的方法实现获取远程网页内容(别忘了还有PhpRPC)

    [php]PHP中file_get_contents()与file_put_contents()函数细节详解 php函数file_get_contents(一) 案例: 早在2010年时候遇到过这样的 ...

  3. 三分钟教你学Git(十六) - 统计

    有时候想统计仓库的情况,比方代码量.贡献者之类的. 1 统计某人的commit数量 git log --author="$(git config --get user.name)" ...

  4. DataSet中取值(转)

    1 DataSet.Table[0].Rows[ i ][ j ] 其中i 代表第 i 行数, j 代表第 j 列数 2 DataSet.Table[0].Rows[ i ].ItemArray[ j ...

  5. dubbo架构演变之路

    背景 (#) 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 单一应用架构 当网站流量很小时, ...

  6. Maven Spring JUnit 在Maven Clean Install时报

    问题: Maven Clean Install时, 遇到报错package org.junit does not exist 明显, Unit Test在Compile阶段就被检查了. 而POM.xm ...

  7. CSS Select 标签取选中文本值

    $("#userDep").find("option:selected").text()

  8. codeforces 626E. Simple Skewness 三分

    题目链接 给n个数, 让你去掉一些数, 使得剩下的数的平均值-中位数的差值最大. 先将数组排序, 然后枚举每一个数作为中位数的情况, 对于每个枚举的数, 三分它的左右区间长度找到一个平均值最大的情况, ...

  9. Unit Tests Tool - <What is “Mock You”> The introduction to moq #Reprinted#

    From: http://www.cnblogs.com/wJiang/archive/2010/02/21/1670632.html Moq即Mock You Framework,故名思意是一个类似 ...

  10. 手动修改VisualStudio IISExpress的配置

    <VisualStudio> <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> ...