Calculation 2

Calculation 2

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

Method:
\ (ANS = \ {n-FRAC * (. 1-n-)} {2} - \ {n-FRAC \ Phi (n-)} {2} \)


Proof:
\ (1 \) total case \ (\ * {n-FRAC (-n-1)} {2} \)
\ (2. \) is not valid for the \ (\ frac {n \ phi (n)} {2} \)
conclusions \ (1: \) if \ ((a, n) = 1 , \) then \ ((na, n) = 1 \)

prove:

\((a,n)=(n-a,a)=(n-a,n)\)

Conclusion \ (2: \) is not valid and is \ (\ frac {n \ phi (n)} {2} \)

\ (\ \ \ \ \ \ 1 \ phi (n) \% 2 = 0 \)

Illegal number of columns \ (a_1, a_2, a_3 ... (n-a _ {\ phi (n) -2}) - (n-a _ {\ phi (n) -1}) - (n-a _ {\ phi (n)}) \)

\ (\ sum_ {i = 1} ^ na_i = \ frac {n \ phi (n)} {2} \)


\ (\ \ \ \ \ \ 2 \ phi (n) \% 2 = 1 \)

Illegal number of columns \ (a_1, a_2, a_3 ... \ frac {n} {2} ... (n-a _ {\ phi (n) -2}) - (n-a _ {\ phi (n) -1}) - (n-a _ {\ phi (n)}) \)

\ (\ Sum_ {i = 1} ^ na_i = \ frac {n \ phi (n)} {2} \)

Sum \ (: \) is not valid for the \ (\ frac {n \ phi (n)} {2} \)

\(\mathfrak{Talk\ is\ cheap,show\ you\ the\ code.}\)

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
# define Type template<typename T>
# define read read1<int>()
Type inline T read1()
{
    T t=0;
    bool ty=0;
    char k;
    do k=getchar(),(k=='-')&&(ty=1);while('0'>k||k>'9');
    do t=(t<<3)+(t<<1)+(k^'0'),k=getchar();while('0'<=k&&k<='9');
    return ty?-t:t;
}
# define int long long
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
int work(int n)
{
    int tn=n;
    for(int i=2;i*i<=n;++i)
        if(!(n%i))
        {
            while(!(n%i))n/=i;
            tn=tn/i*(i-1);
        }
    if(n!=1)tn=tn/n*(n-1);
    return tn;
}
signed main()
{
    for(int n;n=read;)
        printf("%lld\n",(n*(n-1)-n*work(n))/2ll%1000000007ll);
    return 0;
}

Guess you like

Origin www.cnblogs.com/SYDevil/p/11913368.html