poj_2480 Longge's problem(素因子分解+积性函数+欧拉phi函数)
来源:互联网 发布:免费qq群排名优化 编辑:程序博客网 时间:2024/06/05 07:37
Longge's problem
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8297 Accepted: 2765
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.
"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.
A number N per line.
Output
For each N, output ,∑gcd(i, N) 1<=i <=N, a line
Sample Input
26
Sample Output
315
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <stack>#include <bitset>#include <queue>#include <set>#include <map>#include <string>#include <algorithm>#define FOP freopen("data.txt","r",stdin)#define FOP2 freopen("data1.txt","w",stdout)#define inf_LL 4223372036854775807#define inf 0x3f3f3f3f#define maxn 10010#define mod 1000000007#define PI acos(-1.0)#define LL long longusing namespace std;int p[maxn], k[maxn], pn; //n = p1^k1+p2^k2+...void get_factor(int n){ pn = 0; int m = (int)sqrt(n+0.5); for(int i = 2; i <= m; i++) if(n%i == 0) { p[pn] = i, k[pn] = 0; while(n % i == 0){ k[pn]++; n /= i; } pn++; } if(n != 1) { k[pn] = 1; p[pn++] = n; }}int main(){ int n; while(~scanf("%d", &n)) { LL ans = n; get_factor(n); for(int i = 0; i < pn; i++) { ans = ans + ans*k[i]*(p[i]-1)/p[i]; } printf("%lld\n", ans); } return 0;}
0 0
- poj_2480 Longge's problem(素因子分解+积性函数+欧拉phi函数)
- POJ 2480 Longge's problem 解题报告(欧拉函数 + 积性函数)
- POJ 2480 Longge's problem(积性函数之欧拉函数与gcd)
- poj 2480 Longge's problem(积性函数 & 欧拉函数)
- POJ 2480 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 积性函数性质+欧拉函数
- POJ 2048 Longge's problem (欧拉函数 积性函数)
- POJ 2480 Longge's problem (欧拉函数+乘性函数)
- POJ 2480 Longge's problem 欧拉函数
- POJ 2480 Longge's problem(神奇欧拉函数)
- POJ 2480 Longge's problem (欧拉函数)
- POJ2480 Longge's problem 欧拉函数应用
- jvm虚拟机的结构
- 名称空间(XML schema)
- C++ 学习笔记 易错点
- 七种排序算法及其复杂度
- Android app应用多语言切换功能实现
- poj_2480 Longge's problem(素因子分解+积性函数+欧拉phi函数)
- systemui 分析
- Service
- WEB前端开发面试题
- 模拟实现strncpy与极简改进
- Shuffling Machine (20)
- 使用maven搭建一套web
- select into 与 insert into
- [BZOJ1089][SCOI2003]严格n元树(dp+数学相关+高精度)