码迷,mamicode.com
首页 > 其他好文 > 详细

2705: [SDOI2012]Longge的问题

时间:2019-03-28 15:20:02      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:16px   clu   函数   data   NPU   BMI   esc   name   .com   

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 4064  Solved: 2596
[Submit][Status][Discuss]

Description

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

Input

一个整数,为N。

Output

一个整数,为所求的答案。

Sample Input

6

Sample Output

15

HINT

 

0<N<=2^32。

2019.1.1新加数据一组。 

 

欧拉函数

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5 #define LL long long
 6 
 7 int eular(LL n)
 8 {
 9     LL ret=n;
10     LL nn=sqrt(n);
11     for(LL i=2;i<=nn;i++)
12     {
13         if(n%i==0)
14             ret=ret/i*(i-1);
15         while(n%i==0) n/=i;
16     }
17     if(n>1) ret=ret/n*(n-1);
18     return ret;
19 }
20 
21 LL n,ans;
22 
23 int main()
24 {
25     scanf("%lld",&n);
26     LL nn=sqrt(n);
27     for(LL i=1;i<=nn;i++)
28     {
29         if(n%i==0) ans+=i*eular(n/i)+(n/i)*eular(i);
30     }
31     if(nn*nn==n) ans-=eular(nn)*nn;
32     printf("%lld",ans);
33     return 0;
34 }

 

2705: [SDOI2012]Longge的问题

标签:16px   clu   函数   data   NPU   BMI   esc   name   .com   

原文地址:https://www.cnblogs.com/InWILL/p/10615077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!