zoukankan      html  css  js  c++  java
  • loj1370(欧拉函数+线段树)

    传送门:Bi-shoe and Phi-shoe

    题意:给出多个n(1<=n<=1e6),求满足phi(x)>=n的最小的x之和。

    分析:先预处理出1~1e6的欧拉函数,然后建立一颗线段树维护最大值,对于每个n询问大于等于n的最左边下标。

    #pragma comment(linker,"/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <limits.h>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <cstdlib>
    #include <stack>
    #include <vector>
    #include <set>
    #include <map>
    #define LL long long
    #define mod 100000000
    #define inf 0x3f3f3f3f
    #define eps 1e-6
    #define N 1001000
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define PII pair<int,int>
    using namespace std;
    inline LL read()
    {
        char ch=getchar();LL x=0,f=1;
        while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int phi[N+5],prime[N/10],mx[N<<2];
    void init()
    {
        for(int i=2;i<=N;i++)phi[i]=i;
        int tot=0;
        for(int i=2;i<=N;i++)
        {
            if(phi[i]==i)
            {
                for(int j=i;j<=N;j+=i)
                    phi[j]=phi[j]/i*(i-1);
            }
        }
    }
    void Pushup(int rt)
    {
        int ls=rt<<1,rs=ls|1;
        mx[rt]=max(mx[ls],mx[rs]);
    }
    void build(int l,int r,int rt)
    {
        if(l==r)
        {
            mx[rt]=phi[l];
            return;
        }
        int m=(l+r)>>1;
        build(lson);
        build(rson);
        Pushup(rt);
    }
    int query(int x,int l,int r,int rt)
    {
        if(l==r)return l;
        int m=(l+r)>>1;
        if(mx[rt<<1]>=x)return query(x,lson);
        else return query(x,rson);
    }
    int main()
    {
        int T,n,cas=1;
        init();
        build(1,N,1);
        T=read();
        while(T--)
        {
            n=read();
            LL ans=0;
            for(int i=1;i<=n;i++)
            {
                int x=read();
                ans+=query(x,1,N,1);
            }
            printf("Case %d: %lld Xukha
    ",cas++,ans);
        }
    }
    View Code
  • 相关阅读:
    Aircrack-ng破解无线WIFI密码
    隐写术
    数据链路层协议(Ethernet、IEEE802.3、PPP、HDLC)
    OSI七层模型
    异步访问技术Ajax(XMLHttpRequest)
    XML / HTML / XHTML 的区别
    字符集与字符编码
    密码学(对称与非对称加密 哈希算法)
    渗透测试之信息收集
    OWASP-ZAP扫描器的使用
  • 原文地址:https://www.cnblogs.com/lienus/p/4298925.html
Copyright © 2011-2022 走看看