zoukankan      html  css  js  c++  java
  • bzoj 2705 [SDOI2012]Longge的问题——欧拉函数大水题

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2705

    撕逼题。不就是枚举gcd==d,求和phi[ n/d ]么。

    然后预处理sqrt (n)的阶乘,RE得不行。发现用到了大于sqrt (n)的阶乘。

    然后翻看TJ。

    发现phi可以现求!就用那个式子。我竟然都忘了!

    注意最后剩下的一个大于sqrt (i)的质因数。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #define ll long long
    using namespace std;
    const int N=1e5+5;
    ll ans,n;
    ll phi(ll a)
    {
        ll ret=a;
        for(ll i=2;i*i<=a;i++)
            if(a%i==0)
            {
                ret=ret/i*(i-1);
                while(a%i==0)a/=i;
            }
        if(a>1)ret=ret/a*(a-1);
        return ret;
    }
    int main()
    {
        scanf("%lld",&n);
        for(ll i=1;i*i<=n;i++)
            if(n%i==0)
                if(i!=n/i)ans+=i*phi(n/i)+(n/i)*phi(i);
                else ans+=i*phi(n/i);
        printf("%lld
    ",ans);
        return 0;
    }
  • 相关阅读:
    5
    4
    3
    work02
    查看远程库信息(git remote的用法)
    隐藏的文件
    tag相关操作
    分支管理
    git 克隆分支
    git初始化操作
  • 原文地址:https://www.cnblogs.com/Narh/p/9399780.html
Copyright © 2011-2022 走看看