其他分享
首页 > 其他分享> > Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)

Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)

作者:互联网

Coprime Arrays

啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long

using namespace std;

const int N = 2e6 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;
const double eps = 1e-6;
const double PI = acos(-1);

int n, k, miu[N], Pown[N], sum[N];

int Power(int a, int b) {
    int ans = 1;
    while(b) {
        if(b & 1) ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod; b >>= 1;
    }
    return ans;
}

int main() {
    miu[1] = 1;
    for(int i = 1; i < N; i++)
        for(int j = i + i; j < N; j += i)
            miu[j] -= miu[i];
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= k; i++) Pown[i] = Power(i, n);
    int ans = 0, tmp = 0;
    for(int i = 1; i <= k; i++) {
        for(int j = i; j <= k; j += i) {
            sum[j] = ((sum[j] + 1LL * miu[i] * (Pown[j / i] - Pown[j / i - 1])) % mod + mod) % mod;
        }
        tmp = (tmp + sum[i]) % mod;
        ans = (ans + (tmp ^ i)) % mod;
    }
    printf("%d\n", ans);
    return 0;
}

/*
*/

 

标签:const,Arrays,题解,Codeforces,long,int,ans,miu,define
来源: https://www.cnblogs.com/CJLHY/p/10570014.html