zoukankan      html  css  js  c++  java
  • BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)

    题意

    题目链接

    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
    */
    
  • 相关阅读:
    hisi3516/3519开发(二)—xshell连接串口
    linux svn使用
    IdentityServer4 源码介绍
    想写博客
    # VS2019 快捷键插入当前时间
    # 使用 vscode markdown 遇到的问题
    # 学Vue
    teXt使用
    Linux基础
    NopCommerce(Core)学习目录
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10361235.html
Copyright © 2011-2022 走看看