zoukankan      html  css  js  c++  java
  • LightOj1007

    题意: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
    ",t++,sum[f]-sum[e-1]);
        }
        return 0;
    }
  • 相关阅读:
    装饰者模式
    代理模式
    享元模式
    模板模式
    命令模式
    建造者模式
    单例模式
    观察者模式
    迭代器模式
    访问者模式
  • 原文地址:https://www.cnblogs.com/a719525932/p/7700472.html
Copyright © 2011-2022 走看看