【hdu 3501 (数论、欧拉函数)】

Calculation 2

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


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
 
Recommend
zhouzeyong
 1 // Project name : 3501 ( Calculation 2 ) 
 2 // File name    : main.cpp
 3 // Author       : Izumu
 4 // Date & Time  : Fri Jul 13 17:14:43 2012
 5 
 6 
 7 #include <iostream>
 8 #include <stdio.h>
 9 #include <string>
10 #include <math.h>
11 #include <algorithm>
12 using namespace std;
13 
14 ////////////////////////////////////////////////////////////////////////
15 typedef unsigned long long int longint;
16 ////////////////////////////////////////////////////////////////////////
17 longint phi(longint num)
18 {
19     longint sum = 1;
20     for (longint i = 2; i <= sqrt((double long)num); i++)
21     {
22         if (num % i == 0)
23         {
24             while (num % i == 0)
25             {
26                 sum *= i;
27                 num /= i;
28             }
29             sum /= i;
30             sum *= (i - 1);
31         }
32     }
33     if (num != 1)
34     {
35         sum *= (num - 1);
36     }
37     return sum;
38 }
39 ////////////////////////////////////////////////////////////////////////
40 int main()
41 {
42     longint number;
43     while (cin >> number && number)
44     {
45         cout << ((number - 1) * number / 2 - number * phi(number) / 2) % 1000000007 << endl;
46     }
47     return 0;
48 }
49 
50 // end 
51 // ism 
原文地址:https://www.cnblogs.com/ismdeep/p/2590754.html