求a_i 在 [1,k]范围内,gcd(a_1,a_2...,a_n) = 1的a的数组个数。

F(x)表示gcd(a_1,a_2,...,a_n) = i的a的个数

f(x)表示gcd(a_1,a_2,...,a_n) = ki的a的个数(实际上就是i的倍数)

f(x) = segma(x | d) F(d)

F(x) = segma(x | d) mu(d / x) * f(d)

F(1) = segma(d,1,k) mu(d) * f(d)

f(d) = (k / d)^n

由于k变化时f数组会发生变化但为了要避免不断更新f数组,我们把和式换一种方式去求。

由于k增大后,只有k的因子t对应的f数组f(t)加1,因此大可以用筛法枚举因子i,找到该因子的对应倍数j

然后更新答案,其中每次变化贡献的值应为mu(i) * (f(j / i) - f(j / i - 1)),然后更新ans,加上已经枚举完的因子i对应的答案。

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <stack>
using namespace std;
typedef long long ll;
#define T int t_;Read(t_);while(t_--)
#define dight(chr) (chr>='0'&&chr<='9')
#define alpha(chr) (chr>='a'&&chr<='z')
#define INF (0x3f3f3f3f)
#define maxn (2000005)
#define maxm (10005)
#define mod 1000000007
#define ull unsigned long long
#define repne(x,y,i) for(int i=(x);i<(y);++i)
#define repe(x,y,i) for(int i=(x);i<=(y);++i)
#define repde(x,y,i) for(int i=(x);i>=(y);--i)
#define repdne(x,y,i) for(int i=(x);i>(y);--i)
#define ri register int
inline void Read(int &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
inline void Read(ll &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if
(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
/* */
int mu[maxn],isprim[maxn],prim[maxn],len,n,k;
ll sum[maxn],p[maxn];
void mui(){
mu[] = ;
repe(,k,i){
if(!isprim[i]) mu[prim[len++] = i] = -;
repne(,len,j){
if(i * prim[j] > ) break;
isprim[i*prim[j]] = true;
if(i % prim[j] == ) break;
mu[i*prim[j]] = -mu[i];
}
}
}
ll quickpow(ll x,ll y){
ll ans = ;
while(y){
if(y & ) ans = (ans * x) % mod;
x = (x * x) % mod;
y >>= ;
}
return ans;
}
void solve(){
p[] = ,p[] = ;
repe(,k,i) p[i] = quickpow(i,n);
int s = ,ans = ;
repe(,k,i){
for(int j = i;j <= k;j += i) sum[j] = ((sum[j] + (ll)mu[i]*(p[j/i] - p[j/i-])) + mod) % mod;
s = (s + sum[i]) % mod;
ans = (ans + (s^i)) % mod;
}
cout << ans << endl;
}
int main()
{
/// freopen("a.in","r",stdin);
// freopen("b.out","w",stdout);
Read(n),Read(k);
mui();
solve();
return ;
}

---恢复内容结束---

Educational Codeforces Round 36 (Rated for Div. 2) G. Coprime Arrays的更多相关文章

  1. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  2. Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons

    提供两种思路 一种线段树区间更新 另一种用map维护连续的区间,也是题解的思路 第二种很难写(我太渣,看了别人的代码,发现自己写的太烦了) #include<iostream> #incl ...

  3. Educational Codeforces Round 36 (Rated for Div. 2)

    A. Garden time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  4. Educational Codeforces Round 58 (Rated for Div. 2) G 线性基

    https://codeforces.com/contest/1101/problem/G 题意 一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零 题解 根据线性基 ...

  5. Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays

    题目链接 题意:给你两个数x,yx,yx,y,让你构造一些长为yyy的数列,让这个数列的累乘为xxx,输出方案数. 思路:考虑对xxx进行质因数分解,设某个质因子PiP_iPi​的的幂为kkk,则这个 ...

  6. Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem

    题意:给串s,每次询问k个数a,l个数b,问a和b作为后缀的lcp的综合 题解:和bzoj3879类似,反向sam日神仙...lcp就是fail树上的lca.把点抠出来建虚树,然后在上面dp即可.(感 ...

  7. Educational Codeforces Round 51 (Rated for Div. 2) G. Distinctification(线段树合并 + 并查集)

    题意 给出一个长度为 \(n\) 序列 , 每个位置有 \(a_i , b_i\) 两个参数 , \(b_i\) 互不相同 ,你可以进行任意次如下的两种操作 : 若存在 \(j \not = i\) ...

  8. Educational Codeforces Round 48 (Rated for Div. 2)G. Appropriate Team

    题意:求满足条件的(i,j)对数:\(gcd(v,a_i)=x,lcm(v,a_j)=y\) 题解:\(x|a_i,a_j|y\),\(x|y\),考虑质因子p,假设a_i中p次数为a,x中次数为b, ...

  9. Educational Codeforces Round 47 (Rated for Div. 2)G. Allowed Letters 网络流

    题意:给你一个字符串,和每个位置可能的字符(没有就可以放任意字符)要求一个排列使得每个位置的字符在可能的字符中,求字典序最小的那个 题解:很容易判断有没有解,建6个点表示从a-f,和源点连边,容量为原 ...

随机推荐

  1. CPP-网络/通信:POST

    BOOL PostSubmit(CString strUrl,const CString&strPara, CString&strContent){ BOOL bRet=FALSE; ...

  2. Ukulele 调音

    正常的持琴姿势时,从上到下依次是:4,3,2,1弦,音从上往下是:G,C,E,A: 3弦 - C - Do - D - Re 2弦 - E - Mi - F - Fa 4弦 - G -So 1弦 - ...

  3. tableview 删除cell

    正如在以前的帖子说,但是我在转到故事版(StoryBoard)教程之前,我有另外一个问题来回答. 我如何从UITableView删除一行呢? 当人们构建简单的表视图引用程序后,这是另一个常见的​​问题 ...

  4. ios retain copy assign相关

    assign: 简单赋值,不更改索引计数copy: 建立一个索引计数为1的对象,然后释放旧对象retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1 Copy其实是建立了一 ...

  5. ios之UITabelViewCell的自定义(代码实现)

    在用到UITableVIew的时候,经常会自定义每行的Cell 在IOS控件UITableView详解中的下面代码修改部分代码就可以实现自定义的Cell了 [cpp] view plaincopy - ...

  6. bzoj5138 [Usaco2017 Dec]Push a Box

    题目描述: bz luogu 题解: 暴力可以记录$AB$位置转移,这个时候状态是$n^4$的,无法接受. 考虑只记录$A$在$B$旁边时的状态,这个时候状态时$n^2$的. 所以说转移有两种,一种是 ...

  7. linux 5.7.20和5.6.38版本 数据库忘记root密码怎么找回?

    1.    5.6.38版本的数据库密码丢失找回方法: 第一步.关数据库 第二步:mysqld_safe --skip-grant-tables --skip-networking & 第三步 ...

  8. RN在设备上运行

    https://facebook.github.io/react-native/docs/running-on-device.html 在发布之前,最好是在真实的设备上测试一下应用.如果是通过crea ...

  9. 如何用纯 CSS 创作一支诱人的冰棍

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/vrxzMw 可交互视频教 ...

  10. python 列表(增删改查)

    列表 :(列表可以嵌套,列表的中的元素可以为任意) 列表的创建:1.   a = [1, 2, 3] 2.   a = list([1, 2, 3]) 1.查: 索引(下标),都是从0开始 切片 .c ...