POJ 2480 Longge's problem(数论)
来源:互联网 发布:淘宝 真货 编辑:程序博客网 时间:2024/06/01 07:19
题意:给出n,求sigma(gcd(n,i))。
思路:对于n的一个约数g,和n的公约数为g的数的个数为phi(n/g),所以只需要求出sigma(phi(n/i)*i)即可。
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>#include<algorithm>#include<vector>#include<map>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<ctime>#define eps 1e-6#define LL long long#define pii pair<int, int>//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const int MAXN = 1000100;//const int INF = 0x3f3f3f3f;int n;int phi(int n) {int m = (int)sqrt(n+0.5);int ans = n;for(int i = 2; i <= m; i++) if(n%i == 0) {ans = ans / i * (i-1);while(n % i == 0) n /= i;}if(n > 1) ans = ans / n * (n-1);return ans;}int main() { //freopen("input.txt", "r", stdin);while(cin >> n) {LL ans = 0;int m = (int)sqrt(n+0.5); for(int i = 1; i <= m; i++) if(n%i == 0){ ans += (LL)phi(n/i)*i; if(i!=n/i) ans += (LL)phi(i)*(n/i);}cout << ans << endl;} return 0;}
1 0
- POJ 2480 Longge's problem(数论)
- POJ 2480 Longge's problem(数论)
- Longge's problem-数论
- POJ 2480 Longge's Problem
- poj 2480 Longge's problem
- poj 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem (欧拉函数)
- (poj 2480 Longge's problem)<欧拉函数>
- 【poj】 2480 Longge's problem (欧拉函数)
- POJ 2480 : Longge\'s problem - gcd之和
- POJ 2480 Longge 数论
- 1085.Longge's problem (数论,欧拉积性函数)
- POJ 2480 Longge's problem 欧拉函数
- POJ 2480 Longge's problem(神奇欧拉函数)
- POJ 2480 Longge's problem (欧拉函数)
- poj 1191 棋盘分割
- 介绍在Swift2面向协议编程(译文)
- 基于物品的协同过滤中,余弦相似度、皮尔森系数、修正余弦相似度三者的区别
- JavaScript contains
- love2d iOS 脚本打包 & xcode7 真机调试
- POJ 2480 Longge's problem(数论)
- Google Protocol Buffers自带c++,java,python例子程序编译运行
- Protocol Buffers的安装使用和C++/Python入门示例
- node.js中遇到SyntaxError: Use of const in strict mode
- 桌面版Linux提示Enter Password for Default Keyring to Unlock的解决方法
- 使用dumbo开发hadoop streaming程序
- 深入mysql "ON DUPLICATE KEY UPDATE" 语法的分析
- 运用Log和Trace文件排除Oracle Net问题
- 关于Python中的yield