LightOj1007 - Mathematically Hard (欧拉函数)

题意:http://www.lightoj.com/volume_showproblem.php?problem=1007

求[a,b]范围内所有整数的欧拉函数的平方和。欧拉函数:求不大于其本身的与其互质的数的个数。

第一次用这个   结果会爆long long,要用unsigned long long %llu形式;

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
typedef unsigned long long LL;
#define N 5000006
#define Lson rood<<1
#define Rson rood<<1|1
LL sum[N];
int a[N];
void Eular()
{
    for(int i=2;i<N;i++)
    {
        if(!a[i])
        {
            for(int j=i;j<N;j+=i)
            {
                if(a[j]==0) a[j]=j;
                a[j]-=a[j]/i;
            }
        }
    }
    for(int i=1;i<N;i++)
        sum[i]=sum[i-1]+(LL)a[i]*a[i];
}
int main()
{
    Eular();
    int T,t=1;
    scanf("%d",&T);
    while(T--)
    {
        int e,f;
        scanf("%d%d",&e,&f);
        printf("Case %d: %llu\n",t++,sum[f]-sum[e-1]);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/a719525932/p/7700472.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值