http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028

分析:

FFT/NTT板子题...

代码:

NTT板子:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std; const int maxn=500000+5,mod=998244353,G=3; int n,m,L,len1,len2,R[maxn],a[maxn],b[maxn]; char ch[2][maxn]; inline int power(long long x,int y){
long long res=1;
while(y){
if(y&1)
res=res*x%mod;
x=x*x%mod,y>>=1;
}
return res;
} inline void NTT(int *a,int f){
for(int i=0;i<n;i++)
if(i<R[i]) swap(a[i],a[R[i]]);
for(int i=1;i<n;i<<=1){
int wn=power(G,(mod-1)/(i<<1));
if(f==-1) wn=power(wn,mod-2);
for(int j=0;j<n;j+=(i<<1)){
int w=1;
for(int k=0;k<i;k++,w=1LL*w*wn%mod){
int x=a[j+k],y=1LL*w*a[j+k+i]%mod;
a[j+k]=((x+y)%mod+mod)%mod;
a[j+k+i]=((x-y)%mod+mod)%mod;
}
}
}
if(f==-1){
int tmp=power(n,mod-2);
for(int i=0;i<n;i++)
a[i]=1LL*a[i]*tmp%mod;
}
} signed main(void){
scanf("%s",ch[0]);len1=strlen(ch[0])-1;
scanf("%s",ch[1]);len2=strlen(ch[1])-1;
for(int i=0;i<=len1;i++) a[i]=ch[0][len1-i]-'0';
for(int i=0;i<=len2;i++) b[i]=ch[1][len2-i]-'0';
n=max(len1,len2);m=n<<1;for(n=1;n<=m;n<<=1) L++;
for(int i=0;i<n;i++)
R[i]=(R[i>>1]>>1)|((i&1)<<(L-1));
NTT(a,1),NTT(b,1);
for(int i=0;i<n;i++) a[i]=1LL*a[i]*b[i]%mod;
NTT(a,-1);
for(int i=0;i<m;i++)
if(a[i]>=10)
a[i+1]+=a[i]/10,a[i]%=10;
while(!a[m]) m--;
for(int i=m;i>=0;i--) printf("%d",a[i]);puts("");
return 0;
}

  


By NeighThorn

51Nod 1028 大数乘法 V2的更多相关文章

  1. FFT/NTT [51Nod 1028] 大数乘法 V2

    题目链接:51Nod 传送门 没压位,效率会低一点 1.FFT #include <cstdio> #include <cstring> #include <algori ...

  2. 51nod 1028 大数乘法 V2 【FFT模板题】

    题目链接 模板题.. #include<bits/stdc++.h> using namespace std; typedef int LL; typedef double db; nam ...

  3. 51 Nod 1028 大数乘法 V2【Java大数乱搞】

    1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A ...

  4. 1028 大数乘法 V2(FFT or py)

    1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果.   Input 第1行:大数A 第2行:大数B ...

  5. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  6. ACM学习历程—51NOD1028 大数乘法V2(FFT)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...

  7. 51NOD 1027 大数乘法

    1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题   给出2个大整数A,B,计算A*B的结果.   Input 第1行:大数A 第2行:大数B (A,B ...

  8. FFT版题 [51 Nod 1028] 大数乘法

    题目链接:51 Nod 传送门 数的长度为10510^5105,乘起来后最大长度为2×1052\times10^52×105 由于FFT需要把长度开到222的次幂,所以不能只开到2×1052\time ...

  9. 【51NOD1028】大数乘法 V2

    ╰( ̄▽ ̄)╭ 给出2个大整数A,B,计算A*B的结果. (A,B的长度 <= 100000,A,B >= 0) (⊙ ▽ ⊙) 把大整数A看做一个次数界为lenA的多项式A(x),其中x ...

随机推荐

  1. c++异常处理--创建自己的异常处理类

    复习了一下c++中的异常处理! 继承exception类 class myException : public std::exception { public: explicit myExceptio ...

  2. centos 7 安装以及ip配置

    1.安装: root 200M: swap 内存的2倍,如果内存超过4g,最大设为8g就够了: / 剩余: 2.ip配置 (1)动态配置:dhclient ip add (2)静态配置:vi /etc ...

  3. [Wolfgang Mauerer] 深入linux 内核架构 第十三章 系统调用

    作为Linux开发爱好者,从事linux 开发有三年多时间.做过bsp移植,熟悉u-boot代码执行流程:看过几遍<linux 设备驱动程序开发>,分析过kernel启动流程,写过驱动,分 ...

  4. INNODB insert query end state

    innodb_flush_log_at_trx_commit=2 innodb_flush_method=O_DIRECT (for non-windows machine) innodb_buffe ...

  5. 07.VUE学习之解决phpstorm不识别ECMASCRIPT6语法的问题

    此时已经识别:

  6. SpringBoot-Security-用户权限分配-项目搭建

    SpringBoot原则是约定优于配置,简化spring应用开发,去繁从简,产品级别的应用. SpringBoot有哪些优点1.快速创建独立运行的spring项目与主流框架集成 2.使用嵌入式的ser ...

  7. Python3中的列表用法,看这一篇就够了

    类似C语言中的列表用法 ---------------------------------------------------------------------------------------- ...

  8. angularjs的使用技巧

    1. AngularJS的module函数有两种用法, a. 定义一个module, 需要传入2个参数,module('moduleName', []), 第一个参数是新的module名称,第二个参数 ...

  9. 算法训练 Eurodiffusion

    Eurodiffusion /***********并未完全AC***********/ #include<iostream> #include<algorithm> #inc ...

  10. 动态规划:ZOJ1074-最大和子矩阵 DP(最长子序列的升级版)

    To the Max Time Limit:1 Second     Memory Limit:32768 KB Problem Given a two-dimensional array of po ...