51Nod 1028 大数乘法 V2
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的更多相关文章
- FFT/NTT [51Nod 1028] 大数乘法 V2
题目链接:51Nod 传送门 没压位,效率会低一点 1.FFT #include <cstdio> #include <cstring> #include <algori ...
- 51nod 1028 大数乘法 V2 【FFT模板题】
题目链接 模板题.. #include<bits/stdc++.h> using namespace std; typedef int LL; typedef double db; nam ...
- 51 Nod 1028 大数乘法 V2【Java大数乱搞】
1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A ...
- 1028 大数乘法 V2(FFT or py)
1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B ...
- 51nod 1027大数乘法
题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...
- ACM学习历程—51NOD1028 大数乘法V2(FFT)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...
- 51NOD 1027 大数乘法
1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B ...
- FFT版题 [51 Nod 1028] 大数乘法
题目链接:51 Nod 传送门 数的长度为10510^5105,乘起来后最大长度为2×1052\times10^52×105 由于FFT需要把长度开到222的次幂,所以不能只开到2×1052\time ...
- 【51NOD1028】大数乘法 V2
╰( ̄▽ ̄)╭ 给出2个大整数A,B,计算A*B的结果. (A,B的长度 <= 100000,A,B >= 0) (⊙ ▽ ⊙) 把大整数A看做一个次数界为lenA的多项式A(x),其中x ...
随机推荐
- React 服务端渲染最佳解决方案
最近在开发一个服务端渲染工具,通过一篇小文大致介绍下服务端渲染,和服务端渲染的方式方法.在此文后面有两中服务端渲染方式的构思,根据你对服务端渲染的利弊权衡,你会选择哪一种服务端渲染方式呢? 什么是服务 ...
- JS MarcoTasks MicroTasks
JS MarcoTasks MicroTasks 在JS的event loop中,有两种任务队列microtasks和macrotasks microtasks process.nextTick Pr ...
- python 使用requests 请求 https 接口 ,取消警告waring
response = requests.request("POST", url, timeout=20, data=payload, headers=headers, proxie ...
- swpan&expect交互脚本
#!/usr/bin/expectset timeout 30set user USERNAMEset pass PASSWORDspawn sudo pg_dump npi -U admin -p ...
- tp5 修改自带success或error跳转模板页面
tp5 修改自带success或error跳转模板页面 我们在使用tp5或者tp3.2的时候,用的成功或者失败跳转提示页面一般是用框架的.在后续开发过程中,根据实际项目需要,也是可以更改的,在此分享一 ...
- 17.VUE学习之- v-for指令的使用方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Broken robot CodeForces - 24D (概率DP)
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you unders ...
- (JAVA指针),对象引用问题
引出指针 从表面上看JAVA是没有指针的,或者是说,弱化了指针.但是指针在JAVA中还是真真切切存在的.在Java中我们称之为引用. String a;//引用为空 String a = new S ...
- java十分钟速懂知识点——NIO
一.引子 nio是java的IO框架里边十分重要的一部分内容,其最核心的就是提供了非阻塞IO的处理方式,最典型的应用场景就是处理网络连接.很多同学提起nio都能说起一二,但是细究其背后的原理.思想往往 ...
- 01-Flutter移动电商实战-项目学习记录
一直想系统性的学习一下 Flutter,正好看到该课程<Flutter移动电商实战>的百度云资源,共 69 课时,由于怕自己坚持不下去(经常学着学着就不学了),故采用博客监督以记之. 1. ...