题面

题解

SDOI2015 序列统计 比较像

这个无非就是把乘改成了加, NTT 改成了 MTT

再加上了一个小小的容斥 : 拿所有方案减去不合法方案即可

Code

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
const int N = 1005;
const int mod = 20170408;
const double pi = acos(-1);
typedef long long ll;
using namespace std; int n, m, lim, cnt, a[N], b[N], res1[N], res2[N], vis[20000005], stk[5000005], top, P, r[N];
struct Complex
{
double a, b;
Complex(double x = 0, double y = 0) { a = x, b = y; }
Complex operator + (const Complex &p) const { return Complex(a + p.a, b + p.b); }
Complex operator - (const Complex &p) const { return Complex(a - p.a, b - p.b); }
Complex operator * (const Complex &p) const { return Complex(a * p.a - b * p.b, a * p.b + b * p.a); }
} c[N], d[N], e[N], f[N], A[N], B[N], C[N], D[N]; template < typename T >
inline T read()
{
T x = 0, w = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * w;
} void del(int *p)
{
for(int i = 2; i <= m; i++)
{
if(!vis[i]) stk[++top] = i, b[i % P]--;
for(int j = 1; i * stk[j] <= m; j++)
{
vis[i * stk[j]] = 1;
if(!(i % stk[j])) break;
}
}
} void fft(Complex *p, int opt)
{
for(int i = 0; i < lim; i++) if(i < r[i]) swap(p[i], p[r[i]]);
for(int i = 1; i < lim; i <<= 1)
{
Complex rt = Complex(cos(pi / i), opt * sin(pi / i));
for(int j = 0; j < lim; j += (i << 1))
{
Complex w = Complex(1, 0);
for(int k = j; k < j + i; k++, w = w * rt)
{
Complex x = p[k], y = w * p[k + i];
p[k] = x + y, p[k + i] = x - y;
}
}
}
if(opt == -1)
{
for(int i = 0; i < lim; i++)
p[i].a = (ll) (p[i].a / lim + 0.5) % mod;
}
} int sum(int x, int y) { return (1ll * x << y) % mod; } void mul(int *a, int *b, int *ans)
{
for(int i = 0; i < lim; i++)
{
c[i].a = a[i] >> 15, c[i].b = 0, d[i].a = a[i] & 32767, d[i].b = 0;
e[i].a = b[i] >> 15, e[i].b = 0, f[i].a = b[i] & 32767, f[i].b = 0;
}
fft(c, 1), fft(d, 1), fft(e, 1), fft(f, 1);
for(int i = 0; i < lim; i++)
{
A[i] = c[i] * e[i], B[i] = c[i] * f[i];
C[i] = e[i] * d[i], D[i] = d[i] * f[i];
}
fft(A, -1), fft(B, -1), fft(C, -1), fft(D, -1);
for(int i = 0; i < lim; i++)
ans[i] = (((1ll * sum((ll) A[i].a % mod, 30) + sum((ll) B[i].a % mod, 15)) % mod
+ sum((ll) C[i].a % mod, 15)) % mod + sum((ll) D[i].a % mod, 0)) % mod;
for(int i = 0; i < lim; i++)
ans[i] = (1ll * ans[i] + ans[i + P]) % mod, ans[i + P] = 0;
} int main()
{
n = read <int> (), m = read <int> (), P = read <int> ();
for(lim = 1; lim <= 2 * P; lim <<= 1, cnt++); cnt--;
for(int i = 0; i < lim; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << cnt);
for(int i = 0; i < P; i++)
b[i] = a[i] = m / P + (i && i <= m % P);
del(b);
res1[0] = 1, res2[0] = 1;
while(n)
{
if(n & 1)
mul(res1, a, res1), mul(res2, b, res2);
mul(a, a, a), mul(b, b, b);
n >>= 1;
}
printf("%d\n", (res1[0] - res2[0] + mod) % mod);
return 0;
}

MTT太丑了

[题解] [SDOI2017] 序列计数的更多相关文章

  1. 【BZOJ4818】[Sdoi2017]序列计数 DP+矩阵乘法

    [BZOJ4818][Sdoi2017]序列计数 Description Alice想要得到一个长度为n的序列,序列中的数都是不超过m的正整数,而且这n个数的和是p的倍数.Alice还希望 ,这n个数 ...

  2. [bzoj4818][Sdoi2017]序列计数_矩阵乘法_欧拉筛

    [Sdoi2017]序列计数 题目大意:https://www.lydsy.com/JudgeOnline/problem.php?id=4818. 题解: 首先列出来一个递推式子 $f[i][0]$ ...

  3. [Sdoi2017]序列计数 [矩阵快速幂]

    [Sdoi2017]序列计数 题意:长为\(n \le 10^9\)由不超过\(m \le 2 \cdot 10^7\)的正整数构成的和为\(t\le 100\)的倍数且至少有一个质数的序列个数 总- ...

  4. BZOJ_4818_[Sdoi2017]序列计数_矩阵乘法

    BZOJ_4818_[Sdoi2017]序列计数_矩阵乘法 Description Alice想要得到一个长度为n的序列,序列中的数都是不超过m的正整数,而且这n个数的和是p的倍数.Alice还希望 ...

  5. 【BZOJ 4818】 4818: [Sdoi2017]序列计数 (矩阵乘法、容斥计数)

    4818: [Sdoi2017]序列计数 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 560  Solved: 359 Description Al ...

  6. P3702 [SDOI2017]序列计数

    P3702 [SDOI2017]序列计数 链接 分析: 首先可以容斥掉,用总的减去一个质数也没有的. 然后可以dp了,f[i][j]表示到第i个数,和在模p下是j的方案数,矩阵快速幂即可. 另一种方法 ...

  7. BZOJ4818 LOJ2002 SDOI2017 序列计数 【矩阵快速幂优化DP】*

    BZOJ4818 LOJ2002 SDOI2017 序列计数 Description Alice想要得到一个长度为n的序列,序列中的数都是不超过m的正整数,而且这n个数的和是p的倍数. Alice还希 ...

  8. [BZOJ4818][SDOI2017]序列计数(动规+快速幂)

    4818: [Sdoi2017]序列计数 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 972  Solved: 581[Submit][Status ...

  9. [BZOJ 4818/LuoguP3702][SDOI2017] 序列计数 (矩阵加速DP)

    题面: 传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=4818 Solution 看到这道题,我们不妨先考虑一下20分怎么搞 想到暴力,本蒟 ...

随机推荐

  1. C#从零单排上王者系列---元组

    从零单排系列说明 博主最初的想法是想写个蜕茧成蝶的系列文章,后来觉得博客的表现形式很难做到连贯和系统.所以从本篇博客开始博主会选择书中比较重要和不好理解的知识点并结合自己的实际工作经验来讲解,不再是照 ...

  2. putty和psftp命令行参数

    putty和psftp命令行参数 https://the.earth.li/~sgtatham/putty/latest/w32/putty.zip https://the.earth.li/~sgt ...

  3. 关于GPU的传输速度与什么有关??

    1. i5-8250U   1.6GHz 2. PCIE 3  4K 105fps  =  10.45Gps   4K 一帧  = 99.5Mbit 4K YUV444 + mask = 3840*2 ...

  4. IO流的部分类简述

    InputStream 类: InputStream 位于 java.io 包中,它是一个抽象类,表示字节输入流,需要定义 InputStream 子类的应用程序必须总是提供返回下一个输入字节的方法 ...

  5. Python中的一些常用模块1

    OS模块,sys模块,time模块,random模块,序列化模块 os模块是与操作系统交互的一个接口 OS模块简单的来说是一个Python的系统编程操作模块,可以处理文件和目录这些我们日常手动需要做的 ...

  6. vue cli3 打包到tomcat上报错问题

    首先  项目打包步骤 1.vue config.js  添加 publicPath: './', // 公共路径 assetsDir:'static', 2.将代理注释掉 proxy 3.将hash需 ...

  7. 《python解释器源码剖析》第13章--python虚拟机中的类机制

    13.0 序 这一章我们就来看看python中类是怎么实现的,我们知道C不是一个面向对象语言,而python却是一个面向对象的语言,那么在python的底层,是如何使用C来支持python实现面向对象 ...

  8. 《数据结构与算法之美》 <05>链表(下):如何轻松写出正确的链表代码?

    想要写好链表代码并不是容易的事儿,尤其是那些复杂的链表操作,比如链表反转.有序链表合并等,写的时候非常容易出错.从我上百场面试的经验来看,能把“链表反转”这几行代码写对的人不足 10%. 为什么链表代 ...

  9. gojs Diagram Events(图表事件)

    GoJS涵盖了三种基本事件:DiagramEvents(图表事件).InputEvents(输入事件)以及ChangedEvents(变更事件).这一页我们讨论前两种事件:至于最后一种事件请见 Cha ...

  10. [flask初学问题]RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/

    看B站视频学习flask-SQLalchemy时,报错RuntimeError: No application found. Either work inside a view function or ...