欧拉函数之HDU3501 Calculation 2

这道题用到了欧拉函数的一个性质,知道了就是水题了。

性质:小于N与N互质的数和euler(n)*n/2。

这题求的是小于N与N不互质的数之和~

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <sstream>
using namespace std;

#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

typedef long long LL;
const double pi=4.0*atan(1.0);
const int MAXN=105;
const int INF=1<<30;
const LL mould=1000000007;
LL ouler(int n)
{
    LL ans=n;
    for(int i=2;(LL)i*i<=n;i++)
        if(n%i==0)
        {
            ans=ans/i*(i-1);
            while(n%i==0)
                n/=i;
        }
    if(n>1)
        ans=ans/n*(n-1);
    return ans;
}
int main()
{
    LL n;
    while(scanf("%I64d",&n)!=EOF)
    {
        if(n==0)
            return 0;
        if(n==1||n==2)
            printf("0\n");
        else
        {
            LL ans=0;
            ans=((n-1)*n/2-ouler(n)*n/2)%mould;
            printf("%I64d\n",ans);
        }
    
    }


    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值