longge's problem
来源:互联网 发布:何凯文和田静语法知乎 编辑:程序博客网 时间:2024/06/07 20:20
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
__int64 cal(__int64 m)
{
__int64 i=m,k=sqrt(m),flag=m;
for(i=2;i<=k+1;i++) {
if(m%i==0)
flag=flag/i*(i-1);
while(m%i==0)
m/=i;
}
if(m!=1)
flag=flag/m*(m-1);
return flag;
}
int main()
{
__int64 n;
while(~scanf("%I64d",&n)) {
__int64 i=n,k=(__int64)sqrt(n),ans=n,sum=0,m=n;
for(i=2;i<=k;i++) {
if(n%i==0) {
sum+=cal(n/i)*i;
if(i*i!=n)
sum+=cal(n/(n/i))*(n/i);
}
if(m%i==0)
ans=ans/i*(i-1);
while(m%i==0)
m/=i;
}
if(m!=1)
ans=ans/m*(m-1);
printf("%I64d\n",ans+sum+n);
}
return 0;
}
/*
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
*/
- longge's problem
- poj2480 Longge's problem
- Longge's problem-数论
- POJ2480 Longge's problem
- POJ 2480 Longge's Problem
- soj 1085. Longge's problem
- Sicily 1085.Longge's problem
- sicily 1085. Longge's problem
- poj 2480 Longge's problem
- Sicily 1085. Longge's problem
- POJ2480《Longge's problem》题解
- poj 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem
- Longge's problem 隐含了错误 WA
- POJ 2480 : Longge\'s problem - gcd之和
- POJ2480 Longge's problem【乘性函数】
- 用JDBC方法连接Oracle和Mysql数据库
- 小范围求整数的划分(递归实现)
- 木有同步的生产者-消费者
- Math的属性之对数
- 第二遍C++primer->关于变量名和地址的探讨(转载来的文章,供日后参考。)
- longge's problem
- poj3233 - Matrix Power Series-矩阵快速幂
- springsecurity框架
- java--IO流初试
- Android系统移植与调试之------->如何修改Android设备的桌面背景图片
- 4117: Discover
- the euler function
- 【免费Java教学之】怎样学好Java
- FusionCharts简单教程(二)-----使用js加载图像和setDataXML()加载数据