首页 > 其他 > 详细

BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)

时间:2019-02-11 11:59:14      阅读:212      评论:0      收藏:0      [点我收藏+]

题意

题目链接

Sol

开始用反演推发现不会求\(\mu(k)\)慌的一批

退了两步发现只要求个欧拉函数就行了

\(ans = \sum_{d | n} d \phi(\frac{n}{d})\)

理论上来说复杂度是\(O(n)\)的,但是\(d\)的值十分有限。在\(2^{32}\)内最多的约数也只有1920个。

/*

*/
#include<bits/stdc++.h>
#define LL long long 
#define int long long 
const int MAXN = 1e5 + 10, INF = 1e9 + 7;
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
int calc(int N) {
    int res = 1;
    for(int i = 2; i * i <= N; i++) {
        if(N % i == 0) {
            int now = (i - 1); N /= i;
            while(N % i == 0) now *= i, N /= i;
            res *= now;
        }
    }
    if(N != 1) res *= (N - 1);
    return res;
}
signed main() {
    N = read();
    int ans = 0;
    for(int i = 1; i * i <= N; i++) {
        if(N % i == 0) {
            ans += i * calc(N / i);
            if(i != N / i) ans += (N / i) * calc(i);
        }
    }
    cout << ans;
    return 0;
}
/*
3 7
a*b
aebr*ob
*/

BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)

原文:https://www.cnblogs.com/zwfymqz/p/10361235.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!