Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)
啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); int n, k, miu[N], Pown[N], sum[N]; int Power(int a, int b) {
int ans = ;
while(b) {
if(b & ) ans = 1LL * ans * a % mod;
a = 1LL * a * a % mod; b >>= ;
}
return ans;
} int main() {
miu[] = ;
for(int i = ; i < N; i++)
for(int j = i + i; j < N; j += i)
miu[j] -= miu[i];
scanf("%d%d", &n, &k);
for(int i = ; i <= k; i++) Pown[i] = Power(i, n);
int ans = , tmp = ;
for(int i = ; i <= k; i++) {
for(int j = i; j <= k; j += i) {
sum[j] = ((sum[j] + 1LL * miu[i] * (Pown[j / i] - Pown[j / i - ])) % mod + mod) % mod;
}
tmp = (tmp + sum[i]) % mod;
ans = (ans + (tmp ^ i)) % mod;
}
printf("%d\n", ans);
return ;
} /*
*/
Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)的更多相关文章
- 【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) ...
- 【CodeForces】915 G. Coprime Arrays 莫比乌斯反演
[题目]G. Coprime Arrays [题意]当含n个数字的数组的总gcd=1时认为这个数组互质.给定n和k,求所有sum(i),i=1~k,其中sum(i)为n个数字的数组,每个数字均< ...
- CF915G Coprime Arrays 莫比乌斯反演、差分、前缀和
传送门 差分是真心人类智慧--完全不会 这么经典的式子肯定考虑莫比乌斯反演,不难得到\(b_k = \sum\limits_{i=1}^k \mu(i) \lfloor\frac{k}{i} \rfl ...
- SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解
题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...
- HDU 4746 Mophues(莫比乌斯反演)题解
题意: \(Q\leq5000\)次询问,每次问你有多少对\((x,y)\)满足\(x\in[1,n],y\in[1,m]\)且\(gcd(x,y)\)的质因数分解个数小于等于\(p\).\(n,m, ...
- Gym - 101982B Coprime Integers (莫比乌斯反演)
题目链接:http://codeforces.com/gym/101982/attachments 题目大意:有区间[a,b]和区间[c,d],求gcd(x,y)=1,其中x属于[a,b],y属于[c ...
- Codeforces 229E Gifts 概率dp (看题解)
Gifts 感觉题解写的就是坨不知道什么东西.. 看得这个题解. #include<bits/stdc++.h> #define LL long long #define LD long ...
- Codeforces 1155F Delivery Oligopoly dp(看题解)
看别人写的才学会的... 我们考虑刚开始的一个点, 然后我们枚举接上去的一条一条链, dp[mask]表示当前已经加进去点的状态是mask所需的最少边数. 反正就是很麻烦的一道题, 让我自己写我是写不 ...
- Codeforces 809E Surprise me! [莫比乌斯反演]
洛谷 Codeforces 非常套路的一道题,很适合我在陷入低谷时提升信心-- 思路 显然我们需要大力推式子. 设\(p_{a_i}=i\),则有 \[ \begin{align*} n(n-1)an ...
随机推荐
- 缓存系列之二:CDN与其他层面缓存
缓存系列之二:CDN与其他层面缓存 一:内容分发网络(Content Delivery Network),通过将服务内容分发至全网加速节点,利用全球调度系统使用户能够就近获取,有效降低访问延迟,提升服 ...
- dig常用命令
Dig是域信息搜索器的简称(Domain Information Groper),使用dig命令可以执行查询域名相关的任务. ###1. 理解dig的输出结果 $ dig chenrongrong.i ...
- Kendo ui 入门知识点
1. Kendo的继承 varPerson= kendo.Class.extend({...}); var person = new person(); var Parent = kendo.Clas ...
- T-SQL LIKE子句 模糊查询
MS SQL Server LIKE子句用于使用通配符运算符将值与类似值进行比较. 有两个通配符与LIKE运算符结合使用: 百分号(%) 下划线(_) 百分号表示零个,一个或多个字符. 下划线表示单个 ...
- LabVIEW--为设备添加配置文件.ini
需求:我同一个程序下载到两台机器人上,有些参数是不一样的,比如说服务器的ID或者端口,以及存放文件的位置,如果我每次下载之前改程序的话就非常麻烦了(虽然在程序里面是作为全局变量来存的),不利于后期的更 ...
- js 测试性能
console.time('querySelector');for(var i=0; i<1000; i++){document.querySelector('body');}console.t ...
- css之坑
1.background-size要放在background后边才会生效. 2.隐藏滚动条,内容可以滑动 body::-webkit-scrollbar { display: none /* 隐藏滚动 ...
- f11 全屏
function fullScreen() { var el = document.documentElement; var rfs = el.requestFullScreen || el.webk ...
- jQuery传参
<a href="#" onClick="click_scroll('here1');">滚动到here1</a><a href= ...
- 整理oracle 树形查询
注:本文参考了<整理oracle 树形查询> sql树形递归查询是数据库查询的一种特殊情形,也是组织结构.行政区划查询的一种最常用的的情形之一.下面对该种查询进行一些总结: create ...