zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Vue部分知识
    JAVA基础之Map接口
    浏览器渲染机制及五大浏览器、四大内核
    WebPack
    Gulp
    GC垃圾回收机制
    Git操作(及操作github)
    Git、Github和GitLab的区别及与SVN的比较
    Node.js介绍
    JAVA基础之Set接口
  • 原文地址:https://www.cnblogs.com/--lr/p/8362575.html
Copyright © 2011-2022 走看看