Calculation 2
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1264 Accepted Submission (s): 530
Problem DescriptionGiven 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 limit T 1.
InputFor 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.
OutputFor each test case, you shocould print the sum module 1000000007 in a line.
Sample Input3 4 0
Sample Output0 2
AuthorGTmac
Source2010 ACM-ICPC Multi-University Training Contest (7) -- Host by HIT
Recommendzhouzeyong is actually a promotion of Euler's function. If the number is less than or equal to n, the number of the numbers of the n-grams is phi (n). the Euler's function is less than or equal to n. The sum of the numbers of the n-grams is phi (n) * n/2; so sum loss is the answer.
/* Extension of the Euler's formula for finding numbers less than N and N that do not intersect with n in HDU 3501: In a number less than or equal to n, the sum of the numbers that do not intersect with N is PHI (x) * x/2. (N> 1) */# include <stdio. h> # include <iostream> # include <string. h ># include <algorithm> using namespace std; const int MOD = 1000000007; // evaluate the Euler function long eular (long n) {long ret = n; long I; for (I = 2; I * I <= n; I ++) {if (n % I = 0) {ret-= ret/I; while (n % I = 0) n/= I; if (n = 1) break;} if (n> 1) ret-= ret/n; return ret;} int main () {long n; while (scanf ("% I64d", & n), n) {long ans = (n * (n-1) /2% MOD-eular (n) * n/2% MOD + MOD) % MOD; printf ("% I64d \ n", ans);} return 0 ;}