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. humble_USACO

    Humble Numbers For a given set of K prime numbers S = {p1, p2, ..., pK}, consider the set of all num ...

  2. python实战===一键刷屏

    #当按键q的时候,自动输入 “大家好!”并回车键发送!from pynput import keyboard from pynput.keyboard import Key, Controller k ...

  3. 【LOJ6201】【bzoj4939】【YNOI2016】掉进兔子洞

    一道比较简单的莫队…… 用bitset维护三个区间的交元素. #include<bits/stdc++.h> ; ; #define UI unsigned int #define rep ...

  4. Android IPC

    1. 什么是Android IPC IPC:inter-process Commnication跨进程的通信,多进程之间的通信,不同的操作系统有不同的通信方式,Android继承自Linux,但其IP ...

  5. [caffe error] undefined reference to `inflateValidate@ZLIB_1.2.9'

    undefined reference to `inflateValidate@ZLIB_1.2.9' Makefile.config添加一行LINKFLAGS := -Wl,-rpath,$(HOM ...

  6. Redis错误:jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set

    原文链接:http://blog.csdn.net/rchm8519/article/details/48347797 redis.clients.util.Pool.getResource(Pool ...

  7. linux 系统调用fork()

    头文件: #include<unistd.h> #include<sys/types.h> 函数原型: pid_t fork( void); (pid_t 是一个宏定义,其实质 ...

  8. 数据类型转换(计算mac地址)

    [root@localhost test1]# vim 19.py //add #!/usr/bin/python macaddr = '00:0C:29:D1:6F:E9' prefix_mac = ...

  9. 流程控制--if条件

    /* if ....else .... */ [root@localhost test1]# vim .py //ADD #!/usr/bin/python >: print 'hello py ...

  10. linux命令(34):less命令

    1.命令格式: less [参数]  文件 2.命令功能: less 与 more 类似,但使用 less 可以随意浏览文件,而 more 仅能向前移动,却不能向后移动,而且 less 在查看之前不会 ...