HDU3501欧拉函数极重要推论

Posted 不积跬步无以至千里,不积小流无以成江海

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU3501欧拉函数极重要推论相关的知识,希望对你有一定的参考价值。

推论:小于N且与N互质的所有数的和(包括1)为 N*vola(N)/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.

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 should print the sum module 1000000007 in a line.Sample Input

3
4
0

Sample Output

0
2
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
LL n;
LL vola(LL x)
{
    LL res = 1;
    for(LL i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            x/=i;
            res*=(i-1);
            while(x%i==0){x/=i;res*=i;}
        }
    }
    if(x>1)
        res*=(x-1);
    return res;
}
int main()
{
    LL n;
    while(cin>>n&&n)
    {
        LL sum = (n*(n-1))/2;
        sum-=n*vola(n)/2;
        sum%=1000000007;
        cout<<sum<<endl;
    }
    return 0;
}

 

以上是关于HDU3501欧拉函数极重要推论的主要内容,如果未能解决你的问题,请参考以下文章

HDU3501 Calculation 2(欧拉函数)

HDU 3501 Calculation 2

C - Calculation 2 HDU - 3501 (欧拉)

杭电3501Calculation 2 欧拉函数

poj2478-Farey Sequence递推求欧拉函数-欧拉函数的几个性质和推论

HDU 3501 Calculation 2