Educational Codeforces Round 36 (Rated for Div. 2) G. Coprime Arrays
求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的更多相关文章
- 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 < ...
- Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons
提供两种思路 一种线段树区间更新 另一种用map维护连续的区间,也是题解的思路 第二种很难写(我太渣,看了别人的代码,发现自己写的太烦了) #include<iostream> #incl ...
- 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 ...
- Educational Codeforces Round 58 (Rated for Div. 2) G 线性基
https://codeforces.com/contest/1101/problem/G 题意 一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零 题解 根据线性基 ...
- Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays
题目链接 题意:给你两个数x,yx,yx,y,让你构造一些长为yyy的数列,让这个数列的累乘为xxx,输出方案数. 思路:考虑对xxx进行质因数分解,设某个质因子PiP_iPi的的幂为kkk,则这个 ...
- 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即可.(感 ...
- Educational Codeforces Round 51 (Rated for Div. 2) G. Distinctification(线段树合并 + 并查集)
题意 给出一个长度为 \(n\) 序列 , 每个位置有 \(a_i , b_i\) 两个参数 , \(b_i\) 互不相同 ,你可以进行任意次如下的两种操作 : 若存在 \(j \not = i\) ...
- 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, ...
- Educational Codeforces Round 47 (Rated for Div. 2)G. Allowed Letters 网络流
题意:给你一个字符串,和每个位置可能的字符(没有就可以放任意字符)要求一个排列使得每个位置的字符在可能的字符中,求字典序最小的那个 题解:很容易判断有没有解,建6个点表示从a-f,和源点连边,容量为原 ...
随机推荐
- Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being
http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...
- PAT (Basic Level) Practise (中文)-1037. 在霍格沃茨找零钱(20)
PAT (Basic Level) Practise (中文)-1037. 在霍格沃茨找零钱(20) http://www.patest.cn/contests/pat-b-practise/1037 ...
- iOS 常用尺寸
APP ICON: @1x:57*57 @2x:114*114 @3x:171*171 机型 屏幕尺寸 像素(px)pixel 点(pt)point PPI iphone4s 3.5吋 ...
- 洛谷 P2370 P2370 yyy2015c01的U盘
https://www.luogu.org/problemnew/show/P2370 二分+背包 #include <algorithm> #include <iostream&g ...
- 【数位dp】bzoj1799: [Ahoi2009]self 同类分布
各种奇怪姿势的数位dp Description 给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数. Sample Input 10 19 Sample Output 3 HINT [约束条 ...
- 【网络流】[USACO4.2]草地排水Drainage Ditches
用EdmondsKarp可过 题目背景 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水系 ...
- mysql存储过程详解及基于PHP使用实例
mysql存储过程详解 1. 存储过程简介 我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的S ...
- AHB2reg接口转换
assign mcu_xxx_addr = (rd_after_wr_reg || reg_valid_write_trans) ? haddr_reg[ADDR_WIDTH+:] : haddr[A ...
- Jquery 自定义动画同步进行如何实现?
需求描述:我需要对不懂的两个HTML对象进行操作,同时开始动画,同时结束动画. 遇到问题:如果先后对连个对象进行 animate动画,那么第一个会先运行,等第一个运行完了运行第二个,这样就不同步了. ...
- python--内置函数, 匿名函数
一 . 内置函数 什么是内置函数? 就是python给你提供的. 拿来直接⽤的函数, 比如print., input等等. 字符串类型代码的执⾏ eval() 执⾏字符串类型的代码. 并返回最终结果( ...