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 ...
随机推荐
- LGTB 学分块
总时间限制: 10000ms 单个测试点时间限制: 1000ms 内存限制: 65536kB 描述 LGTB 最近在学分块,但是他太菜了,分的块数量太多他就混乱了,所以只能分成 3 块 今天他得 ...
- flask-bootstrap
pip install bootstarp 使用bower安装bootstrap的命令是: bash$ bower install bootstrap不过问题出在如何安装bower上. 官方网站上这样 ...
- python基础 字典排序
stus = [ {"name":"zhang","age":18}, {"name":"lisi" ...
- 十、MySQL 删除数据表
MySQL 删除数据表 MySQL中删除数据表是非常容易操作的, 但是你再进行删除表操作时要非常小心,因为执行删除命令后所有数据都会消失. 语法 以下为删除MySQL数据表的通用语法: DROP TA ...
- PHP使用CURL_MULTI实现多线程采集
$connomains = array( "http://www.baidu.com/", "http://www.hao123.com/", "ht ...
- pandas知识点(数据结构)
1.Series 生成一维数组,左边索引,右边值: In [3]: obj = Series([1,2,3,4,5]) In [4]: obj Out[4]: 0 1 1 2 2 3 3 4 4 5 ...
- Python中的dict
dict_lst = [ ('字典的键必须可哈希',), ('字典的键重复覆盖',), ('字典可迭代') ('增',), ('删',), ('改',), ('查',), ('练习',), ] 字典的 ...
- HDU 6092 01背包变形
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 爬山算法 | Java版HA_TSP
嗯哼,今天记录下采用Java编写的爬山算法(Hill Algorithm)求解TSP问题. 爬山算法与其他智能算法类似,是一种用来求解多峰函数最值的算法,爬山算法的基本思想是新解不劣于当前解则转移,否 ...
- 第5模块闯关CSS练习题
1.列举你知道的css选择器? 说道css选择器,大家都知道有许多种,但是真要你去掰着手指头数一数的话,你可能需要数几分钟.其实这么多选择器,完全可以分为两类: 标签选择器(*是特殊情况),可但标签, ...