r·2^k+1 r k g
3 1 1 2
5 1 2 2
17 1 4 3
97 3 5 5
193 3 6 5
257 1 8 3
7681 15 9 17
12289 3 12 11
40961 5 13 3
65537 1 16 3
786433 3 18 10
5767169 11 19 3
7340033 7 20 3
23068673 11 21 3
104857601 25 22 3
167772161 5 25 3
469762049 7 26 3
998244353 119 23 3
1004535809 479 21 3
2013265921 15 27 31
2281701377 17 27 3
3221225473 3 30 5
75161927681 35 31 3
77309411329 9 33 7
206158430209 3 36 22
2061584302081 15 37 7
2748779069441 5 39 3
6597069766657 3 41 5
39582418599937 9 42 5
79164837199873 9 43 5
263882790666241 15 44 7
1231453023109121 35 45 3
1337006139375617 19 46 3
3799912185593857 27 47 5
4222124650659841 15 48 19
7881299347898369 7 50 6
31525197391593473 7 52 3
180143985094819841 5 55 6
1945555039024054273 27 56 5
4179340454199820289 29 57 3

以上是一份NTT专用模数与原根的对照表……

然后从网上爬了一份NTT代码:http://www.cnblogs.com/candy99/p/6641972.html

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N ((1<<18)+5)
#define MOD 1004535809ll
ll Quick_Pow(ll a,ll p){
if(p==0){
return 1ll;
}
ll res=Quick_Pow(a,p>>1);
res=res*res%MOD;
if((p&1ll)==1ll){
res=(a%MOD*res)%MOD;
}
return res;
}
struct NTT{
int n,rev[N];
ll g;
void ini(int lim) {
g=3;//1004535809,998244353的原根都是3
n=1;
int k=0;
while(n<lim){
n<<=1;
++k;
}
for(int i=0;i<n;++i){
rev[i]=((rev[i>>1]>>1)|((i&1)<<(k-1)));
}
}
void dft(ll a[],int DFT) {
for(int i=0;i<n;++i){
if(i<rev[i]){
swap(a[i],a[rev[i]]);
}
}
for(int l=2;l<=n;l<<=1){
int m=l>>1;
ll wn=Quick_Pow(g,DFT==1 ? (MOD-1ll)/(ll)l : MOD-1ll-(MOD-1ll)/(ll)l);
for(int i=0;i<n;i+=l){
ll w=1;
for(int k=0;k<m;++k){
ll t=w*a[i+k+m]%MOD;
a[i+k+m]=(a[i+k]-t+MOD)%MOD;
a[i+k]=(a[i+k]+t)%MOD;
w=w*wn%MOD;
}
}
}
if(DFT==-1){
ll inv=Quick_Pow(n,MOD-2ll);
for(int i=0;i<n;++i){
a[i]=a[i]*inv%MOD;
}
}
}
void mul(ll a[],ll b[],int len) {
ini(len);
dft(a,1);
dft(b,1);
for(int i=0;i<n;++i){
a[i]=a[i]*b[i];
}
dft(a,-1);
}
}ntt;
int len1,len2,len,c[N];
ll a[N],b[N];
char s1[N],s2[N];
int main() {
// freopen("ntt.in","r",stdin);
while(scanf("%s%s",s1,s2)!=EOF){
memset(c,0,sizeof(c));
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
len1=strlen(s1);
len2=strlen(s2);
for(int i=0;i<len1;++i){
a[i]=s1[len1-i-1]-'0';
}
for(int i=0;i<len2;++i){
b[i]=s2[len2-i-1]-'0';
}
len=len1+len2-1;
ntt.mul(a,b,len);
for(int i=0;i<len;++i){
c[i]=a[i];
}
for(int i=0;i<len;++i){
c[i+1]+=c[i]/10;
c[i]%=10;
}
// if(c[len]){
// ++len;
// }//两个数乘积的长度要么是A+B-1,要么是A+B。
// for(int i=len-1;i>=0;--i){
// printf("%d",c[i]);
// }
// puts("");
for(int i=len;i>=0;--i){
if(c[i]!=0 || i==0){
for(int j=i;j>=0;--j){
printf("%d",c[j]);
}
puts("");
break;
}
}
}
return 0;
}

【NTT】hdu1402 A * B Problem Plus的更多相关文章

  1. 【FFT】hdu1402 A * B Problem Plus

    FFT板子. 将大整数看作多项式,它们的乘积即多项式的乘积在x=10处的取值. #include<cstdio> #include<cmath> #include<cst ...

  2. 【BZOJ3489】A simple rmq problem(KD-Tree)

    [BZOJ3489]A simple rmq problem(KD-Tree) 题面 BZOJ 题解 直接做肯定不好做,首先我们知道我们是一个二维平面数点,但是限制区间只能出现一次很不好办,那么我们给 ...

  3. 【CF903G】Yet Another Maxflow Problem 线段树

    [CF903G]Yet Another Maxflow Problem 题意:一张图分为两部分,左边有n个点A,右边有m个点B,所有Ai->Ai+1有边,所有Bi->Bi+1有边,某些Ai ...

  4. 【BZOJ3489】A simple rmq problem

    [BZOJ3489]A simple rmq problem 题面 bzoj 题解 这个题不强制在线的话随便做啊... 考虑强制在线时怎么搞 预处理出一个位置上一个出现的相同数的位置\(pre\)与下 ...

  5. 【BZOJ3489】A simple rmq problem kd-tree

    [BZOJ3489]A simple rmq problem Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过 ...

  6. 【题解】CF986E Prince's Problem(树上差分+数论性质)

    [题解]CF986E Prince's Problem(树上差分+数论性质) 题目大意: 给定你一棵树,有点权\(val_i\le 10^7\).现在有\(m\)组询问给定参数\(x,y,w\)问你对 ...

  7. 【动态规划】Codeforces 706C Hard problem

    题目链接: http://codeforces.com/contest/706/problem/C 题目大意: n(2 ≤ n ≤ 100 000)个字符串(长度不超过100000),翻转费用为Ci( ...

  8. 【BZOJ】1700: [Usaco2007 Jan]Problem Solving 解题

    [题意]给定n道题,每月末发放工资m,要求从1解到n,每道题需要在当月初付费ai,下月初付费bi,多道题可以安排在同月,求最少月数. [算法]DP [题解]参考自:[bzoj1700]Problem ...

  9. 【NTT】loj#6261. 一个人的高三楼

    去年看过t老师写这题博客:以为是道神仙题 题目大意 求一个数列的$k$次前缀和.$n\le 10^5$. 题目分析 [计数]cf223C. Partial Sums 加强版.注意到最后的式子是$f_i ...

随机推荐

  1. 重写strstr、strcpy、memcpy、memset、atof算法

    #include<stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> ...

  2. HDU 2577 How to Type (字符串处理)

    题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...

  3. vue router mode 设置"hash"与"history"的区别

    router官网的说明如下: ********************************************我是官网说明分隔符--开始**************************** ...

  4. 6.0docker Dockerfile文件

    指令格式 #注释 FROM :基础镜像 MAINTAINER:镜像的作者信息 RUN :指定(构建过程中)当前镜像中运行的命令 EXPOSE :指定运行镜像的容器应用程序所使用的端口 容器但不会打开, ...

  5. MySQL当中的case when then

    其实就相当于if else:而且也可以用if来替代. case whent 条件1 then 条件2 else 条件3 end; 如果条件1成立就执行条件2否则执行条件3 mysql ) end; + ...

  6. Python脚本 - 查询磁盘的读写次数信息

    测试系统为:Centos 6.7 Python版本为: 3.6.4 脚本功能:查看指定磁盘的读写及时间等相关信息 #!/usr/bin/env python3 from collections imp ...

  7. python 异步IO( asyncio) 协程

    python asyncio 网络模型有很多中,为了实现高并发也有很多方案,多线程,多进程.无论多线程和多进程,IO的调度更多取决于系统,而协程的方式,调度来自用户,用户可以在函数中yield一个状态 ...

  8. chromedriver版本 支持的Chrome版本

    在使用selenium测试时,如果选择chrome浏览器,需要将chrome driver的exe文件放在项目下 错误的driver版本,会导致无法正常打开本机的浏览器 以下为对应关系 来自网络 ch ...

  9. sicily 1153. 马的周游问题

    一.题目描述 在一个8 * 8的棋盘中的某个位置有一只马,如果它走29步正好经过除起点外的其他位置各一次,这样一种走法则称马的周游路线,试设计一个算法,从给定的起点出发,找出它的一条周游路线. 为了便 ...

  10. linux删除乱码文件[转载]

    一些乱码文件不可以通过普通的rm命令进行管理.可以通过删除i节点的方式删除. [root@192_168_100_35 musicwap]# ls??,?K?k?ͨa*.?J]?k?Φ??P???Z? ...