一 . Rikka with Subset 

题目: http://acm.hdu.edu.cn/showproblem.php?pid=5829

参考  https://blog.csdn.net/hdxrie/article/details/80961416?utm_source=blogxgwz3

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define ULL unsigned long long
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define dep(i,j,k) for(int i=k;i>=j;i--)
#define INF 0x3f3f3f3f
#define mem(i,j) memset(i,j,sizeof(i))
#define make(i,j) make_pair(i,j)
#define pb push_back
using namespace std;
const LL p = , N = ( << ) + , G = , Gi = ;
LL ksm(LL a,LL b) {
LL ans = ;
while(b) {
if(b & ) ans = ans * a % p;
a = a * a % p;
b >>= ;
}
return ans;
}
int n, m;
LL limit, a[N], b[N], r[N], l;
void NTT(LL *A, int type) {
rep(i, , limit - ) if(i < r[i]) swap(A[i], A[r[i]]);
for(int mid = ; mid < limit; mid <<= ) {
LL Wn = ksm(type == ? G : Gi, (p - ) / (mid << ) );
for(int j = ;j < limit; j += (mid << )) {
LL w = ;
for(int k = ; k < mid; k++, w = (w * Wn) % p) {
int x = A[j + k], y = w * A[j + k + mid] % p;
A[j + k] = ( x + y ) % p;
A[j + k + mid] = (x - y + p) % p;
}
}
}
if (type == -) {
LL inv = ksm(limit, p - );
for (int i = ; i < limit; i++) A[i] = 1ll * A[i] * inv % p;
}
}
LL inv[N], fac[N], invfac[N];
void init() {
invfac[] = fac[] = inv[] = fac[] = invfac[] = 1LL;
rep(i, , N - ) {
fac[i]=(fac[i-]*i)%p;
inv[i] = (p - p / i) * inv[p % i] % p;
invfac[i] = (invfac[i - ] * inv[i]) % p;
}
}
LL A[N];
int main() {
init();
int t;
scanf("%d", &t);
while( t-- ) {
scanf("%d", &n);
mem(a, ); mem(b, );
for (limit = , l = ; limit <= (n << ); l++, limit <<= );
rep(i, , limit - ) r[i] = (r[i >> ] >> ) | ((i & ) << (l - ));
rep(i, , n - ) scanf("%lld", &A[i]);
sort(A, A + n,greater<LL>());
rep(i, , n - ) a[i] = ksm(, n - i) * invfac[i] % p;
rep(i, , n - ) b[i] = fac[i] * A[i] % p;
reverse(b, b + n);
NTT(a, ); NTT(b, );
rep(i, , limit - ) a[i] = a[i] * b[i] % p;
NTT(a, -);
LL ans = 0LL, preans = 0LL; LL coe = inv[];
rep(i, , n) {
ans = coe * invfac[i-] % p * a[n-i] % p;
ans = (ans + preans) % p;
printf("%lld ",ans);
coe = coe * inv[] % p; swap(ans, preans);
}
puts("");
}
return ;
}
/*#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN (1<<18)+5
#define MOD 998244353LL
#define g 3LL
using namespace std;
int n,m,L,T,A[MAXN],rev[MAXN];
long long inv[MAXN],fac[MAXN],invfac[MAXN];
long long a[MAXN],b[MAXN];
long long ans_i,pre_ans_i,coe; inline bool cmp(long long a,long long b){return a>b;} inline long long Quick_MOD(long long a,long long b)
{
long long res=1,base=a;
while (b)
{
if (b&1) res=(res*base)%MOD;
base=(base*base)%MOD;
b>>=1;
}
return res;
} inline void NTT(long long c[],int n,int f)
{
long long w,wn,x,y;
for (int i=0;i<n;i++)
if (i<rev[i]) swap(c[i],c[rev[i]]);
for (int i=1;i<n;i<<=1)
{
wn=Quick_MOD(g,(MOD-1)/(i<<1));
if (!~f) wn=Quick_MOD(wn,MOD-2);
for (int p=i<<1,j=0;j<n;j+=p)
{
w=1LL;
for (int k=0;k<i;k++,w=w*wn%MOD)
{
x=c[j+k];y=c[j+k+i]*w%MOD;
c[j+k]=(x+y)%MOD;c[j+k+i]=(x-y+MOD)%MOD;
}
}
}
if (!~f)
for (int i=0;i<n;i++) c[i]=c[i]*inv[n]%MOD;
return ;
} inline void PreWork()
{
invfac[0]=fac[0]=inv[1]=fac[1]=invfac[1]=1LL;
for (int i=2;i<MAXN;i++)
{
fac[i]=(fac[i-1]*i)%MOD;
inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
invfac[i]=(invfac[i-1]*inv[i])%MOD;
}
return ;
} inline void read(int &x)
{
x=0;char ch=getchar();
while (ch<'0'||ch>'9') ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return ;
} int main()
{
PreWork();
read(T);
while (T--)
{
memset(a,0,sizeof a);memset(b,0,sizeof b);
read(n);
for (m=1,L=0;m<=(n<<1);L++,m<<=1);
for (int i=0;i<m;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(L-1));
for (int i=0;i<n;i++) read(A[i]);
sort(A,A+n,cmp);
for (int i=0;i<n;i++) a[i]=Quick_MOD(2,n-i)*invfac[i]%MOD;
for (int i=0;i<n;i++) b[i]=fac[i]*(long long)A[i]%MOD;
reverse(b,b+n);
NTT(a,m,1);NTT(b,m,1);
for (int i=0;i<m;i++) a[i]=a[i]*b[i]%MOD;
NTT(a,m,-1);
ans_i=pre_ans_i=0LL;coe=inv[2];
for (int i=1;i<=n;i++)
{
ans_i=coe*invfac[i-1]%MOD*a[n-i]%MOD;
ans_i=(ans_i+pre_ans_i)%MOD;
printf("%lld ",ans_i);
coe=coe*inv[2]%MOD;swap(ans_i,pre_ans_i);
}
putchar('\n');
}
return 0;
}*/

二 . 序列统计

题目描述

小C有一个集合S,里面的元素都是小于M的非负整数。他用程序编写了一个数列生成器,可以生成一个长度为N的数列,数列中的每个数都属于集合S。小C用这个生成器生成了许多这样的数列。但是小C有一个问题需要你的帮助:给定整数x,求所有可以生成出的,且满足数列中所有数的乘积mod M的值等于x的不同的数列的有多少个。小C认为,两个数列{Ai}和{Bi}不同,当且仅当至少存在一个整数i,满足Ai≠Bi。另外,小C认为这个问题的答案可能很大,因此他只需要你帮助他求出答案mod 1004535809的值就可以了。

输入输出格式

输入格式:

一行,四个整数,N、M、x、|S|,其中|S|为集合S中元素个数。第二行,|S|个整数,表示集合S中的所有元素。


输出格式:

一行,一个整数,表示你求出的种类数mod 1004535809的值。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define size 3000010
#define ll long long
#define db double
#define il inline
#define rint register int
#define gc getchar()
#define rep(i,s,n) for (register int i=s;i<=n;i++)
#define drep(i,n,s) for (register int i=n;i>=s;--i)
#ifdef WIN32
#else
#define ld "%lld"
#endif
#define Mod 1004535809 using namespace std; il ll r()
{
char c; ll x,f=;
for (c=gc;!isdigit(c);c=gc) if (c=='-') f=-; x=c-'';
for (c=gc;isdigit(c);c=gc) x=x*+c-''; return x*f;
} ll F1[size],F0[size],c[size],A[size],po[size],pv[size];
int Lg,L,l1,l2,rev[size],n,m,S,X,g,pg[size]; il ll ksm(ll x,ll y,ll mod)
{
ll res=;
while (y)
{
if (y&) res=(res*x)%mod;
x=x*x%mod;
y>>=;
}
return res;
} int G(int s)
{
int q[]={};
rep(i,,s-) if ((s-)%i==) q[++q[]]=i;
for (int i=;;i++)
{
bool B=;
for (int j=;j<=q[]&&B;j++) if (ksm(i,q[j],s)==) B=;
if (B) return i;
}
return -;
} void Rader(int tmp)
{
Lg=,L=; while (L<tmp) L<<=,Lg++; L<<=,Lg++;
rep(i,,L-)
for (int t=i,j=;j<=Lg;j++)
rev[i]<<=,rev[i]|=t&,t>>=;
ll I=ksm(,Mod-,Mod);
for (int i=;i<=L;i<<=) po[i]=ksm(,(Mod-)/i,Mod),pv[i]=ksm(I,(Mod-)/i,Mod);
} void dft(ll F[],int sgn)
{
rep(i,,L-) A[i]=F[rev[i]];
rep(i,,L-) F[i]=A[i];
for (int i=;i<=L;i<<=)
{
ll wi=po[i]; if (sgn==-) wi=pv[i];
for (int k=;k<L;k+=i)
{
ll ww=,x=,y=;
rep(j,,i/-)
{
x=F[k+j]; y=ww*F[k+j+i/]%Mod;
F[k+j]=(x+y)%Mod; F[i/+j+k]=(x-y+Mod)%Mod;
ww=(ww*wi)%Mod;
}
}
}
if (sgn==-)
for (ll I=ksm(L,Mod-,Mod),i=;i<L;i++) F[i]=(F[i]*I)%Mod;
} void Ksm(int y)
{
F1[]=;
while (y)
{
dft(F0,);
if (y&)
{
dft(F1,); rep(i,,L-) F1[i]=(F1[i]*F0[i])%Mod;
dft(F1,-);
drep(i,L-,m-) F1[i-m+]=(F1[i-m+]+F1[i])%Mod,F1[i]=;
}
rep(i,,L-) F0[i]=(F0[i]*F0[i])%Mod;
dft(F0,-);
drep(i,L-,m-) F0[i-m+]=(F0[i-m+]+F0[i])%Mod,F0[i]=;
y>>=;
}
} int main()
{
n=r(); m=r(); X=r(); S=r();
g=G(m);
ll Q=,qx;
rep(i,,m-) Q=Q*g%m,pg[Q]=i;
rep(i,,S)
{
qx=r(); if (qx) F0[pg[qx]]=;
}
Rader(m);
Ksm(n);printf("%lld\n",F1[pg[X]]);
return ;
}

NTT 练习的更多相关文章

  1. Tsinsen A1493 城市规划(DP + CDQ分治 + NTT)

    题目 Source http://www.tsinsen.com/A1493 Description 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n个城市, 现在 ...

  2. HDU5322 Hope(DP + CDQ分治 + NTT)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5322 Description Hope is a good thing, which can ...

  3. Codeforces632E Thief in a Shop(NTT + 快速幂)

    题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...

  4. hihoCoder1388 Periodic Signal(2016北京网赛F:NTT)

    题目 Source http://hihocoder.com/problemset/problem/1388 Description Profess X is an expert in signal ...

  5. hihocoder #1388 : Periodic Signal NTT&FFT

    传送门:hihocoder #1388 : Periodic Signal 先来几个大牛传送门:  (模板) NTT long long 版 解法一:因为我们知道FFT会精度不够,所以坚持用NTT,但 ...

  6. FFT,NTT 专题

    学习傅里叶的基本性质及其代码,可以参考大神理解 还有 ACdream 的博客 贴一下NTT的模板: using namespace std; typedef long long ll; int n; ...

  7. [快速数论变换 NTT]

    先粘一个模板.这是求高精度乘法的 #include <bits/stdc++.h> #define maxn 1010 using namespace std; char s[maxn]; ...

  8. NTT

    1 问题描述FFT问题解决的是复数域上的卷积.如果现在的问题是这样:给出两个整数数列$Ai,Bj,0\leq i\leq n-1,0\leq j\leq m-1$,以及素数$P$,计算新数列$Ci=( ...

  9. HDU5829 NTT

    以下这份代码并没有过.但感觉没有问题.不是蜜汁WA就是蜜汁T. #include <cstdio> #include <iostream> #include <cstri ...

  10. NTT【51nod】1514 美妙的序列

    题意:1~n 的全排列中,有多少个排列满足任意从中间切成两段后,左边段的最大值大于右边段的最小值? 例如:n为3时有3种 2 3 1 3 1 2 3 2 1 解释:比如 2 3 1 (2) (3 1) ...

随机推荐

  1. python不同编码方式对应所占字节数

    不同编码方式对应所占字节数 ASCII码中,一个英文字母(不分大小写)占一个字节的空间,一个中文汉字占两个字节的空间.一个二进制数字序列,在计算机中作为一个数字单元,一般为8位二进制数,换算为十进制. ...

  2. 老贾的幸福生活day6 整型和布尔值的转换 字符串讲解 for 循环简介

    整型和布尔值的转换: 整型: python 2 整型 int long(长整型) /获取的是整型 python 3 整型 int 获取的是浮点数(小数) 十进制转二进制: print(bin(36)) ...

  3. Java 面向对象的设计原则

    一. 1.面向对象思想的核心: 封装.继承.多态.   2.面向对象编程的追求: 高内聚低耦合的解决方案: 代码的模块化设计: 3.什么是设计模式: 针对反复出现的问题的经典解决方案,是对特定条件下( ...

  4. hashMap,hashTable,TreeMap,concurrentHashMap区别

    hashMap: 基于哈希表实现 treeMap: 基于二叉树实现,适用于排序 hashTable: 底层还是HashMap,在方法上加了同步 concurrentHashMap: java7底层通过 ...

  5. webmagic学习之路-2:采集安居客经纪人列表

    相比较 1 稍微成熟了一点,会用的东西多了. 正则用的不好,很多东西不会,大神轻喷! package com.action; import java.util.ArrayList; import ja ...

  6. O044、一张图秒懂 Nova 16种操作

    参考https://www.cnblogs.com/CloudMan6/p/5565757.html    

  7. Springboot Hikari Centos 首次连数据库很慢

    前言: springboot项目默认使用了hikari作为数据库连接池,在开发机器上一切正常. 但是把程序部署到Centos7 x64上之后发现,每次首页登录的时候都要停顿几十秒. 于是,在程序启动后 ...

  8. JS的 delete操作符 删除对象属性

    JS如何删除对象中的某一属性 var obj={ name: 'zhagnsan', age: 19 } delete obj.name //true typeof obj.name //undefi ...

  9. css3常用样式

    .box{ //改变轴的方向 flex-direction:column; //两端对齐 justify-content:space-between; //换行 flex-wrap: wrap; // ...

  10. OGG学习笔记02

    实验环境:源端:192.168.1.30,Oracle 10.2.0.5 单实例目标端:192.168.1.31,Oracle 10.2.0.5 单实例 1.模拟源数据库业务持续运行 2.配置OGG前 ...