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. CS229 4.Logistic Regression

  2. 【Git使用】SourceTree+Git简单使用(Windows)(转)

    导读: 本人过去Git的可视化工具用的是TortoiseGit,虽然Android Studio也能进行版本管理,但是用下来,感觉SoureTree这款工具是最舒服的(免费的),下面就给大家介绍下我的 ...

  3. this 基础使用方法

    在Java中,this是调用类中变量和内部类的构造方法的关键词,在对象有同名变量时,可以指定类的变量. 例子1: package example_1; import java.lang.*; publ ...

  4. python2.7 urllib2 爬虫

    # _*_ coding:utf-8 _*_ import urllib2import cookielibimport randomimport refrom bs4 import Beautiful ...

  5. cnblogs博客申请完毕,以后再这里安家落户

    cnblogs博客申请完毕,以后再这里安家落户,之前的博客就不转载了,好好搞技术,安稳过日子.

  6. laravel 的 intervention-image 图像处理笔记

    安装: https://blog.csdn.net/beyond__devil/article/details/62230610 需求: PHP >= 5.4 Fileinfo 扩展 GD库 & ...

  7. flex学习笔记 显示数字步进

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  8. react-native ios打包 、设置图标 启动图片

    在这里只记录xcode 打包操作,申请证书操作,之前已经记录过了. https://www.cnblogs.com/hellovoidworld/p/4127576.html  参考了这篇文章,只是可 ...

  9. Notepadd ++ PluginManager安装

    下载地址https://github.com/bruderstein/nppPluginManager/releases 解压后有2个包plugins和updater 分别放入C:\Program F ...

  10. UI5-学习篇-16-云端SCP-Destination配置

    1.登录路径: https://account.ap1.hana.ondemand.com/#/home/welcome 2.查看云连接器 如下图所示,虚拟主机都已连接且资源可用: 若虚拟主机连接存在 ...