zoukankan      html  css  js  c++  java
  • P2303 [SDOI2012]Longge的问题 我傻QwQ

    莫比乌斯反演学傻了$QwQ$


    思路:推式子?

    提交:2次

    错因:又双叒叕没开$longspace long$ 

    题解:

    $sum_{i=1}^n gcd(i,n)$

    $=sum_{d|n}dsum_{i=1}^{frac{n}{d}} [gcd(i,frac{n}{d})=1]$

    注意到$sum_{i=1}^{frac{n}{d}} [gcd(i,frac{n}{d})=1]$就是与$frac{n}{d}$互质的数的个数。

    $=sum_{d|n}dvarphi(frac{n}{d})$

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    using namespace std;
    #define ull unsigned long long
    #define ll long long
    #define R register ll
    #define pause (for(R i=1;i<=10000000000;++i))
    #define In freopen("NOIPAK++.in","r",stdin)
    #define Out freopen("out.out","w",stdout)
    namespace Fread {
    static char B[1<<15],*S=B,*D=B;
    #ifndef JACK
    #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
    #endif
    inline ll g() {
        R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
        if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
    } inline bool isempty(const char& ch) {return (ch<=36||ch>=127);}
    inline void gs(char* s) {
        register char ch; while(isempty(ch=getchar()));
        do *s++=ch; while(!isempty(ch=getchar()));
    }
    } using Fread::g; using Fread::gs;
    namespace Luitaryi {
    const int N=1<<16+10;
    int n,cnt; ll ans;
    int pri[N>>3]; bool vis[N];
    inline void PRE(int n) { 
        for(R i=2;i<=n;++i) {
            if(!vis[i]) pri[++cnt]=i;
            for(R j=1;j<=cnt&&i*pri[j]<=n;++j) {
                vis[i*pri[j]]=true; if(i%pri[j]==0) break;
            }
        }
    }
    inline ll phi(ll x) { R ret=x;
        for(R i=1;i<=cnt&&1ll*pri[i]*pri[i]<=x;++i) if(x%pri[i]==0) {
            ret=ret/pri[i]*(pri[i]-1); while(x%pri[i]==0) x/=pri[i];
        } if(x>1) ret=ret/x*(x-1); return ret;
    }
    inline void main() {
        n=g(); R lim=sqrt(n); PRE(lim);
        for(R i=1;i<=lim;++i) if(n%i==0) {
            ans+=i*phi(n/i);
            if(i*i!=n) ans+=n/i*phi(i);
        } printf("%lld
    ",ans);
    }
    }
    signed main() {
        Luitaryi::main();
    }

    2019.07.18

  • 相关阅读:
    kali环境下如何安装最新版cobalt strike
    win10结束进程时拒绝访问的处理办法
    Windows下Postgresql数据库的下载与配置方法
    ubuntu下安装及配置git的方法
    运行和控制Nginx
    nginx安装(详解)
    ubuntu安装nginx
    在Windows安装运行Kafka
    linux下安装使用虚拟环境
    《操作系统真象还原》线程
  • 原文地址:https://www.cnblogs.com/Jackpei/p/11211119.html
Copyright © 2011-2022 走看看