Solution -「LOJ #6485」 LJJ 学二项式定理
\(\mathcal{Description}\)
Link.
给定 \(n,s,a_0,a_1,a_2,a_3\),求:
\]
多测,数据组数 \(\le10^5\),\(n\le10^{18}\),其余输入 \(\le10^8\)。
\(\mathcal{Solution}\)
单位根反演板题。记一个函数 \(f\) 有:
f(x)&=\sum_{i=0}^n\binom{n}is^ix^i\\
&=(sx+1)^n
\end{aligned}
\]
问题即求 \(i\bmod4=0,1,2,3\) 时 \(a_i\) 倍 \([x^i]f(x)\) 之和。以 \(i\bmod4=0\) 为例:
\sum_{i=0}^n[4|i]a_0[x^i]f(x)&=\frac{1}4a_0\sum_{i=0}^n\left(\sum_{j=0}^3\omega_4^{ij}\right)\binom{n}is^i\\
&=\frac{1}4a_0\sum_{j=0}^3f(\omega_4^j)
\end{aligned}
\]
直接代四个单位根进去算出来即可。对于其他三个 \(i\bmod4\) 的值,将 \(f\) 的各系数位移就能类似地求出答案。
复杂度 \(\mathcal O(T\log n)\)(\(\times4^2\) 的常数)。
\(\mathcal{Code}\)
/* Clearink */
#include <cstdio>
#define rep( i, l, r ) for ( int i = l, repEnd##i = r; i <= repEnd##i; ++i )
#define per( i, r, l ) for ( int i = r, repEnd##i = l; i >= repEnd##i; --i )
typedef long long LL;
inline LL rint () {
LL x = 0, f = 1; char s = getchar ();
for ( ; s < '0' || '9' < s; s = getchar () ) f = s == '-' ? -f : f;
for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );
return x * f;
}
template<typename Tp>
inline void wint ( Tp x ) {
if ( x < 0 ) putchar ( '-' ), x = -x;
if ( 9 < x ) wint ( x / 10 );
putchar ( x % 10 ^ '0' );
}
const int MOD = 998244353, G = 3, INV4 = 748683265;
LL n;
int w[4], s, a[4];
inline int mul ( const long long a, const int b ) { return a * b % MOD; }
inline int add ( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }
inline int mpow ( int a, int b ) {
int ret = 1;
for ( ; b; a = mul ( a, a ), b >>= 1 ) ret = mul ( ret, b & 1 ? a : 1 );
return ret;
}
inline int f ( const int x ) {
return mpow ( add ( mul ( s, x ), 1 ), n );
}
int main () {
w[0] = 1, w[1] = mpow ( G, MOD - 1 >> 2 );
w[2] = mul ( w[1], w[1] ), w[3] = mul ( w[2], w[1] );
for ( int T = rint (); T--; ) {
n = rint () % ( MOD - 1 ), s = rint ();
rep ( i, 0, 3 ) a[i] = rint ();
int ans = 0;
rep ( r, 0, 3 ) {
int res = 0;
rep ( i, 0, 3 ) {
res = add ( res,
mul ( f ( w[i] ), mpow ( w[r * i & 3], MOD - 2 ) ) );
}
ans = add ( ans, mul ( res, a[r] ) );
}
wint ( mul ( ans, INV4 ) ), putchar ( '\n' );
}
return 0;
}
Solution -「LOJ #6485」 LJJ 学二项式定理的更多相关文章
- 【LOJ#6485】LJJ 学二项式定理(单位根反演)
[LOJ#6485]LJJ 学二项式定理(单位根反演) 题面 LOJ 题解 显然对于\(a0,a1,a2,a3\)分开算答案. 这里以\(a0\)为例 \[\begin{aligned} Ans&am ...
- Solution -「LOJ #6029」「雅礼集训 2017」市场
\(\mathcal{Description}\) Link. 维护序列 \(\lang a_n\rang\),支持 \(q\) 次如下操作: 区间加法: 区间下取整除法: 区间求最小值: 区 ...
- Solution -「LOJ #138」「模板」类欧几里得算法
\(\mathcal{Description}\) Link. \(T\) 组询问,每次给出 \(n,a,b,c,k_1,k_2\),求 \[\sum_{x=0}^nx^{k_1}\left\ ...
- Solution -「LOJ #141」回文子串 ||「模板」双向 PAM
\(\mathcal{Description}\) Link. 给定字符串 \(s\),处理 \(q\) 次操作: 在 \(s\) 前添加字符串: 在 \(s\) 后添加字符串: 求 \(s\ ...
- Solution -「LOJ #150」挑战多项式 ||「模板」多项式全家桶
\(\mathcal{Description}\) Link. 给定 \(n\) 次多项式 \(F(x)\),在模 \(998244353\) 意义下求 \[G(x)\equiv\left\{ ...
- Solution -「LOJ #6053」简单的函数
\(\mathcal{Description}\) Link. 积性函数 \(f\) 满足 \(f(p^c)=p\oplus c~(p\in\mathbb P,c\in\mathbb N_+) ...
- 「LOJ#10051」「一本通 2.3 例 3」Nikitosh 和异或(Trie
题目描述 原题来自:CODECHEF September Challenge 2015 REBXOR 1≤r1<l2≤r2≤N,x⨁yx\bigoplus yx⨁y 表示 ...
- 「LOJ#10056」「一本通 2.3 练习 5」The XOR-longest Path (Trie
#10056. 「一本通 2.3 练习 5」The XOR-longest Path 题目描述 原题来自:POJ 3764 给定一棵 nnn 个点的带权树,求树上最长的异或和路径. 输入格式 第一行一 ...
- LOJ6485 LJJ 学二项式定理 解题报告
LJJ 学二项式定理 题意 \(T\)组数据,每组给定\(n,s,a_0,a_1,a_2,a_3\),求 \[ \sum_{i=0}^n \binom{n}{i}s^ia_{i\bmod 4} \] ...
随机推荐
- HBase文档学习顺序
1.<HBase基础概念知识学习> https://www.toutiao.com/i6774215329498268164/ 2.<VM安装CentOS6.5> https: ...
- 安霸pipeline简述之YUV域的处理
YUV域处理模块的详细介绍: YUV域的处理主要是rgb_to_yuv_matrix,chroma_scale,ASF(空域降噪),MCTF(时域降噪),SharpenB(锐化模块). RGB2YUV ...
- testng 的常用注解
常用注解如下: @BeforeSuite: 此注解的方法会在当前测试集合中的任一测试用例前执行 @AfterSuite: 此注解的方法会在当前测试集合中的所有测试程序结束后执行 @BeforeTest ...
- markdownFormat
对文档编辑主要还是用wps,因为以前毕业论文都是用的它来编排(刚开始用wps毕业论文的时候真的是用的想吐,感觉非常不好用,而且功能太多但对于自己需要的功能又偏偏找不到),用过几次后还觉得用它编辑文 ...
- 将待授权的数据库的dbowner指派给该用户
USE 数据库goEXEC dbo.sp_changedbowner N'账号'
- 【刷题-LeetCode】207. Course Schedule
Course Schedule There are a total of numCourses courses you have to take, labeled from 0 to numCours ...
- 面试突击17:HashMap除了死循环还有什么问题?
面试合集:https://gitee.com/mydb/interview 本篇的这个问题是一个开放性问题,HashMap 除了死循环之外,还有其他什么问题?总体来说 HashMap 的所有" ...
- request.getServletContext()爆红问题
ServletRequest的getServletContext方法是Servlet3.0添加的,这个可以看一下官方文档 http://docs.oracle.com/javaee/6/api/jav ...
- web.xml最新配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmln ...
- l线程池抓取lianjia
1. 线程池 的应用 from multiprocessing.dummy import Pool import requests from lxml import etree url="h ...