# bzoj2705 [SDOI2012]Longge的问题

## Description

Longge的数学成绩非常好，并且他非常乐于挑战高难度的数学问题。现在问题来了：给定一个整数N，你需要求出∑gcd(i, N)(1<=i <=N)。

6

15

## HINT

【数据范围】

 1 //It is made by wfj_2048~
2 #include <algorithm>
3 #include <iostream>
4 #include <complex>
5 #include <cstring>
6 #include <cstdlib>
7 #include <cstdio>
8 #include <vector>
9 #include <cmath>
10 #include <queue>
11 #include <stack>
12 #include <map>
13 #include <set>
14 #define il inline
15 #define RG register
16 #define ll long long
17 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
18
19 using namespace std;
20
21 ll n,m,ans;
22
23 il ll phi(RG int n){
24     RG ll x=n;
25     for (RG ll i=2;i<=m;++i){
26     if (n%i) continue;
27     x=x/i*(i-1);
28     while (!(n%i)) n/=i;
29     }
30     if (n>1) x=x/n*(n-1); return x;
31 }
32
33 il void work(){
34     cin>>n; m=sqrt(n);
35     for (RG ll i=1;i<=m;++i){
36     if (n%i) continue;
37     ans+=i*phi(n/i);
38     if (i<n/i) ans+=(n/i)*phi(i);
39     }
40     cout<<ans; return;
41 }
42
43 int main(){
44     File("longge");
45     work();
46     return 0;
47 }

posted @ 2017-03-18 15:11  wfj_2048  阅读(138)  评论(0编辑  收藏  举报