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
    */
    
  • 相关阅读:
    线段的类
    计算三角形的类
    关于狗的类
    [poj2234] Matches Game
    bzoj[2655] calc
    拉格朗日插值和牛顿插值 菜鸟教程
    NOI模拟赛(3.15) sequence(序列)
    NOI模拟赛(3.13)Hike (远行)
    二分图讲解
    NOI模拟赛(3.8)Problem B
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10361235.html
Copyright © 2011-2022 走看看