题面

题解

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. Mysql连接数设置

    在使用MySQL数据库的时候,经常会遇到这么一个问题,就是“Can not connect to MySQL server. Too many connections”-mysql 1040错误,这是 ...

  2. C++编译 C # 调用方法

    C++编译    C # 调用方法 编译时使用  public ref class ABC {   ... }; 调用时  右键---引用 --- 添加dll引用  即可

  3. 批量删除checkbox前台后台

    <%@ page contentType="text/html;charset=UTF-8" %><%@ include file="/WEB-INF/ ...

  4. vmware 虚拟机扩展 liunx系统硬盘空间

    参考一下以下博客 https://www.cnblogs.com/yongdaimi/p/9050155.html https://blog.csdn.net/daemon_2017/article/ ...

  5. No valid host was found. There are not enough hosts available-----openstack建虚拟机直接报错

    目录 No valid host was found. There are not enough hosts available-----openstack建虚拟机直接报错 一.问题现象: 二.解决思 ...

  6. Image Processing and Analysis_15_Image Registration:HAIRIS: A Method for Automatic Image Registration Through Histogram-Based Image Segmentation——2011

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  7. 09 Windows编程——键盘消息

    焦点窗口:接收到这个键盘事件的窗口称为有输入焦点的窗口.具有输入焦点的窗口要么是活动窗口,要么是活动窗口的子孙窗口. 活动窗口:活动窗口通常是很好鉴别的.它总是最上层的窗口——也就是说,它的父窗口句柄 ...

  8. Vs2017 NetCode Mvc EF Mysql 整合1

    1  运行环境   vs2017   NetCode2.0 2 NuGet  MySql.Data.EntityFrameworkCore 8.0.18 3  源代码 https://github.c ...

  9. jmeter——参数化、关联、断言

    1.jmeter——参数化 三种方式: ${变量名} 1.1用户定义的变量 比如注册,登录都得用到手机号码,那就把手机号码自定义为变量 1)添加一个线程组--注册.登录HTTP请求--察看结果树--用 ...

  10. springboot 使用 @data 插件,减少代码量

    一.idea 安装 lombok 插件 二.重启 idea 三.添加依赖 <dependency> <groupId>org.projectlombok</groupId ...