首页 > 其他 > 详细

Coprime Arrays CodeForces - 915G (数论水题)

时间:2019-04-01 22:24:44      阅读:143      评论:0      收藏:0      [点我收藏+]

反演一下可以得到$b_i=\sum\limits_{d=1}^i{\mu(i)(\lfloor \frac{i}{d} \rfloor})^n$

整除分块的话会T, 可以维护一个差分, 优化到$O(nlogn+klogk)$

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl ‘\n‘
#define DB(a) ({REP(i,1,n) cout<<a[i]<<‘ ‘;hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head




const int N = 2e6+10;
int n, k, mu[N];
ll po[N], sum[N];

int main() {
	scanf("%d%d", &n, &k);
	mu[1] = 1;
	REP(i,1,N-1) { 
		for (int j=2*i; j<=N-1; j+=i) mu[j]-=mu[i];
		po[i] = qpow(i,n);
	}
	ll ans = 0;
	REP(i,1,k) { 
		if (mu[i]) for (int j=i; j<=k; j+=i) { 
			sum[j]+=mu[i]*(po[j/i]-po[j/i-1]);
		}
		(sum[i]+=sum[i-1])%=P;
		if (sum[i]<0) sum[i]+=P;
		ans+=i^sum[i];
	}
	printf("%lld\n", (ans%P+P)%P);
}

 

Coprime Arrays CodeForces - 915G (数论水题)

原文:https://www.cnblogs.com/uid001/p/10639078.html

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