传送门


差分是真心人类智慧……完全不会

这么经典的式子肯定考虑莫比乌斯反演,不难得到\(b_k = \sum\limits_{i=1}^k \mu(i) \lfloor\frac{k}{i} \rfloor^n\)

直接做是\(O(n\sqrt{n})\)的不够优秀,但是我们需要求的是\(b_1\)到\(b_K\)而不是单独的一个\(b\),这是最重要的一个性质。

考虑每一个数\(p\)对\(b_1\)到\(b_k\)的贡献。因为\(\mu(p)\)不变,所以对于\(\forall k \in Z_+ ,\)数\(p\)对\(b_{kp}\)到\(b_{(k+1)p-1}\)的贡献是一致的,都是\(\mu(p) k^n\)。既然对于一段区间的贡献相同,那就差分一下,最后前缀和统计答案即可。

总复杂度为预处理\(n\)次方的\(O(klogn)\)加上差分时的\(O(klogk)\)。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<vector>
#include<cmath>
#include<random>
#include<cassert>
//This code is written by Itst
using namespace std; inline int read(){
int a = 0;
char c = getchar();
bool f = 0;
while(!isdigit(c) && c != EOF){
if(c == '-')
f = 1;
c = getchar();
}
if(c == EOF)
exit(0);
while(isdigit(c)){
a = a * 10 + c - 48;
c = getchar();
}
return f ? -a : a;
} #define ll long long
const int MAXN = 2e6 + 3 , MOD = 1e9 + 7;
int powx[MAXN] , prime[MAXN] , mu[MAXN] , cf[MAXN];
bool nprime[MAXN];
int cnt , N , K; inline int poww(ll a , int b){
int times = 1;
while(b){
if(b & 1)
times = times * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return times;
} void init(){
for(int i = 1 ; i <= K ; ++i)
powx[i] = poww(i , N);
mu[1] = 1;
for(int i = 2 ; i <= K ; ++i){
if(!nprime[i]){
prime[++cnt] = i;
mu[i] = -1;
}
for(int j = 1 ; prime[j] * i <= K ; ++j){
nprime[prime[j] * i] = 1;
if(i % prime[j] == 0)
break;
mu[prime[j] * i] = mu[i] * -1;
}
}
} int main(){
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
//freopen("out","w",stdout);
#endif
N = read();
K = read();
init();
for(int i = 1 ; i <= K ; ++i)
for(int j = 1 ; j * i <= K ; ++j)
(cf[j * i] += mu[i] * (powx[j] - powx[j - 1] + MOD) % MOD) %= MOD;
int ans = 0;
for(int i = 1 ; i <= K ; ++i){
cf[i] = (0ll + MOD + cf[i] + cf[i - 1]) % MOD;
ans = (ans + (cf[i] ^ i)) % MOD;
}
cout << ans;
return 0;
}

CF915G Coprime Arrays 莫比乌斯反演、差分、前缀和的更多相关文章

  1. 【CodeForces】915 G. Coprime Arrays 莫比乌斯反演,前缀和,差分

    Coprime Arrays CodeForces - 915G Let's call an array a of size n coprime iff gcd(a1, a2, ..., *a**n) ...

  2. 【CodeForces】915 G. Coprime Arrays 莫比乌斯反演

    [题目]G. Coprime Arrays [题意]当含n个数字的数组的总gcd=1时认为这个数组互质.给定n和k,求所有sum(i),i=1~k,其中sum(i)为n个数字的数组,每个数字均< ...

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

    Coprime Arrays 啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊. #include<bits/stdc++.h> #define LL long long ...

  4. CF915G Coprime Arrays (莫比乌斯反演)

    CF915G Coprime Arrays 题解 (看了好半天终于看懂了) 我们先对于每一个i想,那么 我们设 我们用莫比乌斯反演 有了这个式子,可比可以求出△ans呢?我们注意到,由于那个(i/d) ...

  5. Gym - 101982B Coprime Integers (莫比乌斯反演)

    题目链接:http://codeforces.com/gym/101982/attachments 题目大意:有区间[a,b]和区间[c,d],求gcd(x,y)=1,其中x属于[a,b],y属于[c ...

  6. CF585E-Present for Vitalik the Philatelist【莫比乌斯反演,狄利克雷前缀和】

    正题 题目链接:https://www.luogu.com.cn/problem/CF585E 题目大意 给出一个大小为\(n\)的可重集\(T\),求有多少个它的非空子集\(S\)和元素\(x\)满 ...

  7. F. Coprime Subsequences 莫比乌斯反演

    http://codeforces.com/contest/803/problem/F 这题正面做了一发dp dp[j]表示产生gcd = j的时候的方案总数. 然后稳稳地超时. 考虑容斥. 总答案数 ...

  8. nyoj CO-PRIME 莫比乌斯反演

    CO-PRIME 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 This problem is so easy! Can you solve it? You are ...

  9. [HAOI2011][bzoj2301] Problem b [莫比乌斯反演+容斥原理+分块前缀和优化]

    题面: 传送门 有洛谷就尽量放洛谷链接呗,界面友好一点 思路: 和HDU1695比较像,但是这一回有50000组数据,直接莫比乌斯反演慢慢加的话会T 先解决一个前置问题:怎么处理a,c不是1的情况? ...

随机推荐

  1. filter(ele)过滤数组

    filter也是一个常用的操作,它用于把Array的某些元素过滤掉,然后返回剩下的元素. 例如,在一个Array中,删掉偶数,只保留奇数,可以这么写: function remove(arr) { l ...

  2. Tsung 超详细的的tsung性能测试资料

    超详细的的tsung性能测试资料 by:授客 QQ:1033553122 由于篇幅问题,采用链接分享的形式 下载连接:理解Tsung配置文件 下载连接:基准测试方法 下载连接:Tsung XML配置文 ...

  3. 喜闻乐见-Android应用的生命周期

    本文主要讲述了App的启动流程.Application的生命周期以及进程的回收机制. 在绝大多数情况下,每一个Android应用都在自己的Linux进程中运行.当需要运行某些代码时,进程就会被创建.进 ...

  4. android recovery 升级时间与速度研究

    从android4.4到现在android7.1升级,现在的升级包越来越大,一个system分区大小都分配了2G,整个升级包达到了接近500M, 升级包解压之后1G+,奇怪的是,发现了两个不同批次的板 ...

  5. 动态导入模块:__import__、importlib、动态导入的使用场景

    相关内容: __import__ importlib 动态导入的使用场景 首发时间:2018-02-23 16:06 __import__: 功能: 是一个函数,可以在需要的时候动态导入模块 使用: ...

  6. 从零自学Java-8.创建第一个对象

    1.创建对象:2.使用属性描述对象:3.确定对象的行为:4.合并对象:5.从其他对象继承:6.转换对象和其他类型的信息. 程序NewRoot2:计算输入数的算数平方根并输出 package com.j ...

  7. office远程代码执行(CVE-2017-11882)

    office远程代码执行(CVE-2017-11882) 影响版本: MicrosoftOffice 2000 MicrosoftOffice 2003 MicrosoftOffice 2007 Se ...

  8. [转]mysql和redis的区别

    转自https://www.cnblogs.com/zxh1297/p/9394108.html 1.mysql和redis的数据库类型 mysql是关系型数据库,主要用于存放持久化数据,将数据存储在 ...

  9. 给JDK提的一个bug(关于AbstractQueuedSynchronizer.ConditionObject)

    1. 背景 之前读JUC的AQS源码,读到Condition部分,我当时也写了一篇源码阅读文章--(AbstractQueuedSynchronizer源码解读--续篇之Condition)[http ...

  10. IE8以下兼容

    <!--[if lt IE 9]><script type="text/javascript">alert('IE版本太低,请升级后使用');</sc ...