HDU——T 3501 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
",(zz-(x*phi(x)>>1))%mod);
32     }
33     return 0;
34 }
——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
原文地址:https://www.cnblogs.com/Shy-key/p/7305098.html