loj #6247. 九个太阳
求
$\sum\limits_{i=1}^n [k | i] \times C_n^i$
膜 $998244353$
$n \leq 10^{15},k \leq 2^{20}$
$k$ 是 $2$ 的正整数次方
sol:
“不看题解拿头做” 系列
考虑构造一个序列 $a_i$ 满足只有 $[k|i]$ 时是 $1$,其它时候是 $0$
之后就开始神仙了起来
构造 $k$ 次单位根 $\omega _k = g^{\frac{p-1}{k}}$,发现 $\frac{1}{k} \times \sum\limits_{j=0}^{k-1} \omega _k^{i \times j} = [k | i]$
代入原式得到 $\sum\limits_{i=1}^n \frac{1}{k} \times \sum\limits_{j=0}^{k-1} \omega _k^{i \times j} \times C_n^i$
根据二项式定理 $\sum\limits_{i=0}^n C_n^i \times x^i = (x+1)^n$,可以化简
$\frac{1}{k} \times \sum\limits_{j=0}^{k-1} (\omega_k ^j + 1)^n$
这就可以直接求了
#include <bits/stdc++.h>
#define LL long long
using namespace std;
#define rep(i, s, t) for (register int i = (s), i##end = (t); i <= i##end; ++i)
#define dwn(i, s, t) for (register int i = (s), i##end = (t); i >= i##end; --i)
inline LL read() {
LL x = , f = ; char ch = getchar();
for (; !isdigit(ch); ch = getchar())if (ch == '-')f = -f;
for (; isdigit(ch); ch = getchar()) x = * x + ch - '';
return x * f;
}
const int mod = ;
inline int ksm(int x, int t) {
int res = ;
for(; t; x = 1LL * x * x % mod, t = t >> ) if(t & ) res = 1LL * x * res % mod;
return res;
}
int main() {
LL n = read() % (mod-), k = read();
int ans = ;
int wn = ksm(, (mod-) / k), w = ksm(, (mod-) / k);
rep(i, , k-) {
(ans += ksm(w + , n)) %= mod;
w = 1LL * w * wn % mod;
}
ans = 1LL * ans * ksm(k, mod - ) % mod;
cout << ans << endl;
}
loj #6247. 九个太阳的更多相关文章
- loj #6247. 九个太阳 k次单位根 神仙构造 FFT求和原理
LINK:九个太阳 不可做系列. 构造比较神仙. 考虑FFT的求和原理有 \(\frac{1}{k}\sum_{j=0}^{k-1}(w_k^j)^n=[k|n]\) 带入这道题的式子. 有\(\su ...
- [BZOJ 5252][LOJ 2478][九省联考2018] 林克卡特树
[BZOJ 5252][LOJ 2478][九省联考2018] 林克卡特树 题意 给定一个 \(n\) 个点边带权的无根树, 要求切断其中恰好 \(k\) 条边再连 \(k\) 条边权为 \(0\) ...
- [LOJ #2473] [九省联考2018] 秘密袭击coat
题目链接 洛谷. LOJ,LOJ机子是真的快 Solution 我直接上暴力了...\(O(n^2k)\)洛谷要\(O2\)才能过...loj平均单点一秒... 直接枚举每个点为第\(k\)大的点,然 ...
- [LOJ] 分块九题 4
https://loj.ac/problem/6280 区间修改,区间求和. 本来线段树的活. //Stay foolish,stay hungry,stay young,stay simple #i ...
- [LOJ] 分块九题 3
https://loj.ac/problem/6279 区间修改,区间查询前驱. TLE无数,我觉得这代码最精髓的就是block=1000. 谜一样的1000. 两个启示: 块内可以维护数据结构,比如 ...
- [LOJ] 分块九题 2
https://loj.ac/problem/6278 区间修改,查询区间第k大. 块内有序(另存),块内二分. 还是用vector吧,数组拷贝排序,下标搞不来.. //Stay foolish,st ...
- [LOJ] 分块九题 1
https://loj.ac/problem/6277 区间修改,单点查询. //Stay foolish,stay hungry,stay young,stay simple #include< ...
- [LOJ] 分块九题 8
区间查询数值+整体赋值 维护tag代表整个区间被赋成了tag[i] 用pushdown操作,而不是修改了再check. 不压缩代码了,调起来心累,长点有啥不好. //Stay foolish,stay ...
- [LOJ] 分块九题 7
区间加法,区间乘法,单点查询. 洛谷线段树2 屡清加法乘法的关系,定义答案为 a*mut+add 对于整块: 新的乘w,mut和add都要乘w 新的加w,add加w //Stay foolish,st ...
随机推荐
- XSS - html过滤
JS 根据白名单过滤HTML http://jsxss.com/zh/index.html 方案一: java的一个方案, 可以参考: http://winnie825.iteye.com/bl ...
- LeetCode:螺旋矩阵||【59】
LeetCode:螺旋矩阵||[59] 题目描述 给定一个正整数 n,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵. 示例: 输入: 3 输出: [ [ 1, 2, 3 ...
- Apache Shiro:【1】Shiro基础及Web集成
Apache Shiro:[1]Shiro基础及Web集成 Apache Shiro是什么 Apache Shiro是一个强大且易于使用的Java安全框架,提供了认证.授权.加密.会话管理,与spri ...
- Apache NiFi 开发 安装说明
系统环境: vmware安装的centos6.7虚拟机 jdk1.8版本 maven库3.3.9版本(在使用源码编译启动的时候需要修改配置文件与当前使用的maven版本匹配,最低使用版本好像是3.1. ...
- ZOJ 3959 Problem Preparation 【水】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 AC代码 #include <cstdio> ...
- C# TreeView,递归循环数据加载到treeView1中
TblAreaBLL bll = new TblAreaBLL(); private void button1_Click(object sender, EventArgs e) { LoadData ...
- DEC VT100 terminal
- 【leetcode刷题笔记】Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- 重用UITableViewCell对象的概念
重用UITableViewCell对象 UITableView控件十分常见,基本上我们随意打开一款App都能见到,它被用来列表展示数据,而其中的每一行内容都是一个cell对象 我们知道手机设备上的内存 ...
- 关于form表单中button按钮自动提交问题
坑:点击确认按钮,form表单提交2次,发送后台2次请求 //错误代码: <Button id="btnSubmit" name="btnSubmit" ...