hdu3501

maksyuki 发表于 oj 分类,标签:
0

Calculation 2

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

2010 ACM-ICPC Multi-University Training Contest(7)——Host by HIT

 

题目类型:Euler函数

算法分析:首先用一下欧拉函数GetEuler(n)求一下1~n中与n互质的质因子的个数,然后就要用到一个比较常用的定理:如果gcd(n,i)==1,那么就有gcd(n,n-i)==1; 于是题目的要求是小于n并且与n不互质的所有数的和,这里我们可以先求与n互质的所有数的和为sum = n*(Euler(n) / 2) 。最后用所有数的和减去sum即可