Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N.

"Oh, I know, I know!" Longge shouts! But do you know? Please solve it.

Input

Input contain several test case. 
A number N per line. 

Output

For each N, output ,∑gcd(i, N) 1<=i <=N, a line

Sample Input

2
6

Sample Output

3
15
翻译:给一个数n,1<=i<=n,求gcd(i,n)之和。
解题过程:
令d=gcd(i,n),d必然是n的因子,并且是i和n的最大公因子。
则gcd(i/d,n/d)=1。令y=n/d,通过y求出与y互质的数的个数,然后对这个数量乘以最大公因子d,累加。
 #include <iostream>
#include<stdio.h>
#include <algorithm>
#include<string.h>
#include<cstring>
#include<math.h>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std; ll euler(ll x)
{
ll res=x;
for(ll i=;i*i<=x;i++)
{
if(x%i==)
{
res=res/i*(i-);
while(x%i==)
x=x/i;
}
}
if(x>)
res=res/x*(x-);
return res;
} int main()
{
ll n,sum;
while(scanf("%lld",&n)!=EOF)
{
sum=;
ll i;
for(i=;i*i<=n;i++)
{
if(n%i==)
sum+=i*euler(n/i)+(n/i)*euler(i);
}
i--;
if(i*i==n)
sum-=i*euler(i);
printf("%lld\n",sum);
}
return ;
}
 

poj2480-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 欧拉函数—————∑gcd(i, N) 1<=i <=N

    Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6383   Accepted: 2043 ...

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

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

  4. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

  5. Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1959  Solved: 1229[Submit][ ...

  6. 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数

    题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...

  7. BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)

    题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...

  8. [SDOI2012] Longge的问题 - 欧拉函数

    求 \(\sum\limits_{i=1}^{n}gcd(i,n)\) Solution 化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\) 筛出欧拉函数暴力求 ...

  9. UVa 10837 A Research Problem 欧拉函数

    题意: 给你一个欧拉函数值 phi(n),问最小的n是多少. phi(n) <= 100000000 , n <= 200000000 解题思路: 对于欧拉函数值可以写成 这里的k有可能是 ...

  10. Bzoj-2705 Longge的问题 欧拉函数

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2705 题意: 求 sigma(gcd(i,n), 1<=i<=n<2^3 ...

随机推荐

  1. 推荐7个GitHub上不错的Python机器学习项目

    1.Pylearn2 [Star:2633] Pylearn是一个让机器学习研究简单化的基于Theano的库程序. 2. Scikit-learn [Star:32449] Scikit-learn是 ...

  2. hive的select重命名字段显示成中文

    select '越南'as `版本`, viplevel, t.dbname, t.account, FightPower from ods t where dt = '2017-03-08' and ...

  3. Jquery在表格中搜索关键字

    <!DOCTYPE html><html><head> <title>ddd</title></head><body> ...

  4. <spark> ~/spark/conf/spark-default.conf 配置文件

    因为看到我参考的Hadoop/spark集群搭建的文档中的都没有对 /spark-default.conf 的配置 合理地对 /spark-default.conf  进行配置,能够提高执行效率 -- ...

  5. Heap Allocation Profiles (heap=sites)

    基于JDK-6,使用的类不同,展示的信息可能不同,内容一样的javac -J-agentlib:hprof=heap=sites Hello.java percent live alloc’ed st ...

  6. openstack placement

  7. 46.纯 CSS 创作一个在容器中反弹的小球

    原文地址:https://segmentfault.com/a/1190000015221260 练习地址:https://scrimba.com/c/c3GEWmTb 感想: 原来animation ...

  8. range和xrange

    在python2.7中range()某个区间后,内存会立即创建区间内的所有数值,严重浪费内存,所以就出现了xrange():每次循环的时候生成一个数值 在python3版本中不存在xrange,只有r ...

  9. add_featurelayer_to_map

    var jsonFS = { "geometryType": "esriGeometryPolygon", "features": [ { ...

  10. Centos7 下搭建SVN + Apache 服务器

    1. 安装httpd 安装httpd服务: $ sudo yum install httpd 检查httpd是否安装成功: $ httpd -version Server version: Apach ...