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

Description

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

Source

POJ Contest,Author:Mathematica@ZSU
 
 /*

 题意:∑gcd(i, N) 1<=i <=N。由于N 2^31.
刚开始想用欧拉求得1的个数,再求N的素因子,用容斥
来求解。发现,就算是求得的素因子,也不最大公约数。 HUD的一道题,提供了思路。 枚举吧。
if(N%i==0)
{
最大公约数为1的时候,有几个。欧拉值(N/1);
最大公约数为2的时候,有几个。欧拉值(N/2);
.....
} */ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; __int64 Euler(__int64 n)
{
__int64 i,temp=n;
for(i=;i*i<=n;i++)
if(n%i==)
{
while(n%i==)
n=n/i;
temp=temp/i*(i-);
}
if(n!=)
temp=temp/n*(n-);
return temp;
} int main()
{
__int64 n,i,sum,k;
while(scanf("%I64d",&n)>)
{
sum=;
for(i=;i*i<=n;i++)
{
if(n%i==)
sum=sum+Euler(n/i)*i;
k=n/i;
if(n%k== && k!=i)
sum=sum+Euler(n/k)*k;
}
printf("%I64d\n",sum);
}
return ;
}

POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N的更多相关文章

  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 积性函数

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

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

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

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

  6. poj 3090 &amp;&amp; poj 2478(法雷级数,欧拉函数)

    http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...

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

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

  8. POJ 2478 Farey Sequence(欧拉函数前n项和)

    A - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

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

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

随机推荐

  1. python 实现获取电脑IP、主机名、Mac地址

    import socket import uuid # 获取主机名 hostname = socket.gethostname() #获取IP ip = socket.gethostbyname(ho ...

  2. 世界线(bzoj2894)(广义后缀自动机)

    由于春希对于第二世代操作的不熟练,所以刚使用完\(invasion process\)便掉落到了世界线之外,错综复杂的平行世界信息涌入到春希的意识中.春希明白了事件的真相. 在一个冬马与雪菜同时存在的 ...

  3. 关于使用Iscroll.js异步加载数据后不能滑动到最底端的问题解决方案

    关于使用Iscroll.js异步加载数据后不能滑动到最底端,拉到最下边又弹回去的问题困扰了我老半天,相信很多朋友都遇到了.我刚好不小心解决了,和大家分享一下.由于各种忙,下边就直接上代码吧. (前提是 ...

  4. MVC4删除 pages引发的异常 System.Web.Optimization找不到引用

    在MVC4的开发中,如果创建的项目为空MVC项目,那么在App_Start目录下没有BundleConfig.cs项的内容,在手动添加时在整个库中都找不到:System.Web.Optimizatio ...

  5. 首次进入页面的时候用js刷新页面

    window.onload = function(){ var url=document.location.href; //获取浏览器访问栏里的地址 if( url.indexOf("tim ...

  6. #阿里云#云服务器部署Django(基础篇)

    前言 本人能力有限,本文只是简单介绍基础部署流程,没有过多考虑系统安全等因素,请谅解.初学者参考了解,大神勿喷. 纯测试部署,采用阿里云ECS,系统Ubuntu 16.04 64位,部署采用nginx ...

  7. rabbitmq系列二 之工作队列

    ---恢复内容开始--- 1.工作队列的简介 在上一篇中,我们已经写了一个从已知队列中发送和获取消息的程序,在这里,我们创建一个工作队列(work queue), 会发送一些耗时的任务给多个工作者.模 ...

  8. [WiX]Component Rules 101

    原文:http://robmensching.com/blog/posts/2003/10/18/component-rules-101 I've been debating with myself ...

  9. 3、Xamarin Forms 调整安卓TabbedPage 下置

    降低学习成本是每个.NET传教士义务与责任. 建立生态,保护生态,见者有份.   教程晦涩难懂是我的错误. 对于默认的TabbedPage 上面进行页面切换 上面是安卓默认的情况 对我们大部分人来说都 ...

  10. redis集群配置及运行命令(windows和centos)附Python测试范例代码

    表示配置主服务器器的IP和端口 slaveof <masterip> <masterport> # 设置slave是否是只读的.从2.6版起,slave默认是只读的. slav ...