soj 1085. Longge's problem
来源:互联网 发布:淘宝官方短链接 编辑:程序博客网 时间:2024/06/05 08:36
题意:
求 ∑gcd(i, N) 1<=i <=N,(1<N<2^31)
思路:
枚举N的所有因子d,与N的gcd为d的数有Eular(N/d)个。
于是∑gcd(i, N) 1<=i <=N就等于∑Eular(N/d),d|N。
代码:
#include <cstdio>typedef long long LL;LL n, ans;LL Eular(LL x){LL ret = x;for (LL i = 2; i*i <= x; ++ i){if (x % i == 0){while (x % i == 0) x /= i;ret = ret/i*(i-1);}}if (x != 1) ret = ret/x*(x-1);return ret;}int main(){while (~scanf("%lld", &n)){ans = 0;LL i = 1;for (i = 1; i*i < n; ++ i){if (n % i == 0){ans += i*Eular(n/i);ans += n/i*Eular(i);}}if (i*i == n) ans += i*Eular(i);printf("%lld\n", ans);}}
- soj 1085. Longge's problem
- Sicily 1085.Longge's problem
- sicily 1085. Longge's problem
- Sicily 1085. Longge's problem
- longge's problem
- poj2480 Longge's problem
- Longge's problem-数论
- POJ2480 Longge's problem
- POJ 2480 Longge's Problem
- poj 2480 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
- 1085.Longge's problem (数论,欧拉积性函数)
- soj 1792. Hengheng's Problem
- Longge's problem 隐含了错误 WA
- ARM和thumb指令的区别
- JQuery Mobile入门——不同类型的文本输入
- C#发现之旅第一讲 C#-XML开发
- public void doFilter(ServletRequest request, ServletResponse response,
- 【OpenCV】图像几何变换:旋转,缩放,斜切
- soj 1085. Longge's problem
- Android高手进阶教程(二十五)之---Android 中的AIDL!!!
- Spring 如何初始化一个容器,( 加载xml 文件 )
- mac 安装django
- 【数据结构】排序算法:希尔、归并、快速、堆排序
- DirectShow Filter 编译时遇到的问题
- 最短路—1001
- 为什么同时使用commons-logging和Log4j
- 最短路—1002