HDU——T3501 Calculation 2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU——T3501 Calculation 2相关的知识,希望对你有一定的参考价值。

http://acm.hdu.edu.cn/showproblem.php?pid=3501

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4548    Accepted Submission(s): 1878


Problem Description
Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1.
 

 

Input
For each test case, there is a line containing a positive integer N(1 ≤ N ≤ 1000000000). A line containing a single 0 follows the last test case.
 

 

Output
For each test case, you should print the sum module 1000000007 in a line.
 

 

Sample Input
3 4 0
 

 

Sample Output
0 2
 

 

Author
GTmac
 
Source
 
欧拉函数得和==phi(n)*n/2;
md 还是见识少。。
 1 #include <algorithm>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 #define LL long long
 7 const LL mod(1000000007);
 8 const LL N(1000000000+5);
 9 LL x;
10 
11 LL phi(LL x)
12 {
13     LL ret=1;
14     for(LL i=2;i*i<=x;i++)
15         if(x%i==0)
16         {
17             x/=i;
18             ret*=i-1;
19             for(;x%i==0;)
20                 ret*=i,x/=i;
21         }
22     if(x>1) ret*=x-1;
23     return ret;
24 }
25 
26 int main()
27 {
28     for(;scanf("%lld",&x)&&x;)
29     {
30         LL zz=(x-1)*x>>1;
31         printf("%lld\n",(zz-(x*phi(x)>>1))%mod);
32     }
33     return 0;
34 }

 

以上是关于HDU——T3501 Calculation 2的主要内容,如果未能解决你的问题,请参考以下文章

hdu_3502_Calculation 2

Calculation 2 HDU - 3501

hdu 3501 Calculation 2

C - Calculation 2 HDU - 3501 (欧拉)

HDU 3501 Calculation 2

HDU3501 Calculation 2(欧拉函数)