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,和源点连边,容量为原 ...
随机推荐
- Bootstrap历练实例:危险样式按钮
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...
- javascript基础知识 (八) BOM学习笔记
一.什么是BOM BOM(Browser Object Model)即浏览器对象模型. BOM提供了独立于内容 而与浏览器窗口进行交互的对象: 由于BOM主要用于管理窗口 ...
- Git学习——版本切换
版本回退 回退到前面几个版本的命令如下: git reset --hard HEAD^ //回退到前一个版本 git reset --hard HEAD^^ //回退到前前一个版本 git reset ...
- docker系列之file基本操作
dockerfile基础操作 Dockerfile 是记录了镜像是如何被构建出来的配置文件, 可以被 docker 直接执行以创建一个镜像. 它的样子: FROM ubuntu:14.04 MAINT ...
- C语言获取Shell返回结果
Linux编程时候,如果我们需要调用shell命令或脚本通常使用system方法.如system("ls") 该方法返回值为0或-1,即成功或失败.而有的时候我们想要获取shell ...
- 《嵌入式linux应用程序开发标准教程》笔记——6.文件IO编程
前段时间看APUE,确实比较详细,不过过于详细了,当成工具书倒是比较合适,还是读一读这种培训机构的书籍,进度会比较快,遇到问题时再回去翻翻APUE,这样的效率可能更高一些. <嵌入式linux应 ...
- Python中摘要算法MD5,SHA1讲解
摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示).摘要算法就是通过摘要函数f()对任意长度的数据data计算出固定长度的摘要di ...
- android 之 service
在Activity中设置两个按钮,分别为启动和关闭Service: bt01.setOnClickListener(new Button.OnClickListener() { @Override ...
- 三、harbor部署之SSL
1 签名证书与自签名证书 签名证书:由权威颁发机构颁发给服务器或者个人用于证明自己身份的东西. 自签名证书:由服务器自己颁发给自己,用于证明自己身份的东西,非权威颁发机构发布. 2 openssl简介 ...
- c++ - 在终端中,cout不显示任何内容
g++ 是一个编译器,它将源代码转换成可以执行程序,但不运行它. 你必须亲自运行程序. g++ 生成的程序的默认名称是 a.out ( 因为历史原因),因此你将运行它作为 $./a.out 如果要 ...