Problem Statement

You are given positive integers $N$ and $K$. Find the number, modulo $998244353$, of integer sequences $\bigl(f(0), f(1), \ldots, f(2^N-1)\bigr)$ that satisfy all of the following conditions:

  • $0\leq f(x)\leq K$ for all non-negative integers $x$ ($0\leq x \leq 2^N-1$).
  • $f(x) + f(y) = f(x \,\mathrm{AND}\, y) + f(x \,\mathrm{OR}\, y)$ for all non-negative integers $x$ and $y$ ($0\leq x, y \leq 2^N-1$)

Here, $\mathrm{AND}$ and $\mathrm{OR}$ denote the bitwise AND and OR, respectively.

Constraints

  • $1\leq N\leq 3\times 10^5$
  • $1\leq K\leq 10^{18}$

Input

Input is given from Standard Input in the following format:

$N$ $K$

Output

Print the number, modulo $998244353$, of integer sequences that satisfy the conditions.


Sample Input 1

2 1

Sample Output 1

6

The following six integer sequences satisfy the conditions:

  • $(0,0,0,0)$
  • $(0,1,0,1)$
  • $(0,0,1,1)$
  • $(1,0,1,0)$
  • $(1,1,0,0)$
  • $(1,1,1,1)$

Sample Input 2

2 2

Sample Output 2

19

Sample Input 3

100 123456789123456789

二进制的题,考虑拆位处理。

那么会发现,当我们确定了 \(f(0),f(1)\cdots f(2^n)\) 时,整个函数就确定了

具体写出来,就是 \(f(2^{p_1}+2^{p_2}+\cdots+2^{p_m})=(\sum\limits_{i=1}^mf(2^{p_i})-f(0))+f(0)\)

这个式子可以直接打表推出来

那么此时我们知道了所有 \(f(2^p_i)-f(0)\) 的值,我们能否知道有多少个合法的 \(f(0)\)?

注意有 \(f(x)\) 的限制,所以要满足任意的数,\(0\le (\sum\limits_{i=1}^m(f(2^{p_i})-f(0)))+f(0)\le K\)

上面这个式子的最大值和最小值一定是所有正数的和(设为 \(s1\))和所有负数的和(设为s2),那么

\[s2+f(0)\ge 0,s1+f(0)\le k,-s2\le f(0)\le K-s1
\]

共有 \(K-s1+s2+1\) 种选法

注意到 \(s1-s2=\sum\limits_{i=0}^n|f(2^i)|\)

我们可以往这个方向去列式子。枚举最后的绝对值之和。

\[\sum\limits_{i=n}^{K+1}(K-i+1)C_{i-1}^{n-1}
\]
\[=(K+1)\sum\limits_{i=n}^{K+1}C_{i-1}^{n-1}-\sum\limits_{i=n}^{K+1}iC_{i-1}^{n-1}
\]
\[=(K+1)\sum\limits_{i=n}^{K+1}C_{i-1}^{n-1}-n\sum\limits_{i=n}^{K+1}C_i^n(融入公式)
\]
\[=(K+1)C_{K+1}^n-nC_{K+2}^{n+1}(上指标求和)
\]
\[=C_{K+1}^{n+1}(通分可得,不写了)
\]

此时我们还要给每个数分配正负,发现0我们无法分配。枚举有多少个非0点,然后给答案加上 \(C_{K+1}^{i+1}\times 2^i\times C_n^i\)

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5,P=998244353;
int n,f[N],iv[N],inv[N],c[N],ans;
long long k;
int C(int x,int y)
{
return 1LL*f[x]*iv[y]%P*iv[x-y]%P;
}
int main()
{
scanf("%d%lld",&n,&k);
c[f[0]=f[1]=iv[0]=iv[1]=inv[1]=c[0]=1]=(k+1)%P;
for(int i=2;i<N;i++)
{
f[i]=1LL*f[i-1]*i%P;
inv[i]=(P-P/i)*1LL*inv[P%i]%P;
iv[i]=1LL*iv[i-1]*inv[i]%P;
c[i]=c[i-1]*((k-i+2)%P)%P*inv[i]%P;
}
for(int i=0,pw=1;i<=n;i++,(pw<<=1)%=P)
(ans+=1LL*pw*C(n,i)%P*c[i+1]%P)%=P;
// printf("%d %d %d\n",i,pw,c[i+1]);
printf("%d",ans);
}

[ARC144D] AND OR Equation的更多相关文章

  1. CodeForces460B. Little Dima and Equation

    B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  3. HDU 5937 Equation

    题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...

  4. coursera机器学习笔记-多元线性回归,normal equation

    #对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...

  5. CF460B Little Dima and Equation (水题?

    Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...

  6. Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)

    ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...

  7. ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分

    Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  8. [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...

  9. hdu 2199 Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. SGU 106 The equation

    H - The equation Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. 《SQLi-Labs》01. Less 1~5

    @ 目录 前言 索引 Less-1 题解 原理 Less-2 题解 Less-3 题解 Less-4 题解 Less-5 题解 原理 sqli.开启新坑. 前言 对于新手,为了更加直观的看到 sql ...

  2. C#开发的基础工具类集合 - 开源研究系列文章

    今天发布一个基础工具类代码集合. 以前有发布过一个类似的类库(见博文: Magical平台类库代码分享 ),不过那个版本有点久了,也没有这次这个全面,这次发布的是一个很多地方用到的基础类库代码. 1. ...

  3. 安装软件提示 "无法完成操作, 因为文件包含病毒或潜在的垃圾软件" 如何处理

    在Windows端安装一些小众电脑软件的时候,经常会遇到无法安装的问题,比较常见的情况是会提示 "无法完成操作, 因为文件包含病毒或潜在的垃圾软件", 或者提示"不能执行 ...

  4. WebStrom提交代码到GitLab报错Error: Cannot find any-observable implementation nor global.Observable.

    项目场景: 前端代码完成后,提交代码 问题描述 提交代码到GitLab时,因自动检测机制导致项目提交失败 C:\D\insper\inspur_works\custom-manage-front\no ...

  5. 研发效能|DevOps 是运维还是开发?

    DevOps 到底是 Dev还是Ops?答:属于研发工程师序列,偏向研发域,而不是运维域. DevOps是研发工程师 DevOps 主要服务的对象就是所有产研团队的人员,与产研团队打交道比较多,相互配 ...

  6. Solution -「洛谷 P5659」「CSP-S 2019」树上的数

    Description Link. 联赛原题应该都读过吧-- Solution Part 0 大致思路 主要的思路就是逐个打破,研究特殊的数据得到普通的结论. Part 1 暴力的部分分 暴力的部分分 ...

  7. pandas -- DataFrame的级联以及合并操作

    博客地址:https://www.cnblogs.com/zylyehuo/ 开发环境 anaconda 集成环境:集成好了数据分析和机器学习中所需要的全部环境 安装目录不可以有中文和特殊符号 jup ...

  8. 基于 ACK Serverless 解锁你家萌宠的 AI 形象

    基于 ACK Serverless 解锁你家萌宠的 AI 形象详情      1. 计费说明 必看!!必看!!必看!! 本实验为付费体验,需要消耗账号费用.体验后若不再需要使用,请及时释放资源,避免持 ...

  9. Arduino – Turn LED ON and OFF With Button

    In this Arduino tutorial I will show you how to turn an LED on and off with a push button. In fact, ...

  10. splay + 垃圾回收 知识点与例题的简要讲解

    splay 简要讲解 前置芝士:普通二叉树 splay tree是一个越处理越灵活的数据结构,通过splay(伸展)操作,使整棵树的单次查询时间复杂度接近于O(log n),整棵树的高度也接近于log ...