#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define N 50500*2
const double PI = acos(-1.0);
struct Vir
{
double re, im;
Vir(double _re = ., double _im = .) :re(_re), im(_im){}
Vir operator*(Vir r) { return Vir(re*r.re - im*r.im, re*r.im + im*r.re); }
Vir operator+(Vir r) { return Vir(re + r.re, im + r.im); }
Vir operator-(Vir r) { return Vir(re - r.re, im - r.im); }
};
void bit_rev(Vir *a, int loglen, int len)
{
for (int i = ; i < len; ++i)
{
int t = i, p = ;
for (int j = ; j < loglen; ++j)
{
p <<= ;
p = p | (t & );
t >>= ;
}
if (p < i)
{
Vir temp = a[p];
a[p] = a[i];
a[i] = temp;
}
}
}
void FFT(Vir *a, int loglen, int len, int on)
{
bit_rev(a, loglen, len); for (int s = , m = ; s <= loglen; ++s, m <<= )
{
Vir wn = Vir(cos( * PI*on / m), sin( * PI*on / m));
for (int i = ; i < len; i += m)
{
Vir w = Vir(1.0, );
for (int j = ; j < m / ; ++j)
{
Vir u = a[i + j];
Vir v = w*a[i + j + m / ];
a[i + j] = u + v;
a[i + j + m / ] = u - v;
w = w*wn;
}
}
}
if (on == -)
{
for (int i = ; i < len; ++i) a[i].re /= len, a[i].im /= len;
}
}
char a[N * ], b[N * ];
Vir pa[N * ], pb[N * ];
int ans[N * ];
int main()
{
while (scanf("%s%s", a, b) != EOF)
{
int lena = strlen(a);
int lenb = strlen(b);
int n = , loglen = ;
while (n < lena + lenb) n <<= , loglen++;
for (int i = , j = lena - ; i < n; ++i, --j)
pa[i] = Vir(j >= ? a[j] - '' : ., .);
for (int i = , j = lenb - ; i < n; ++i, --j)
pb[i] = Vir(j >= ? b[j] - '' : ., .);
for (int i = ; i <= n; ++i) ans[i] = ; FFT(pa, loglen, n, );
FFT(pb, loglen, n, );
for (int i = ; i < n; ++i)
pa[i] = pa[i] * pb[i];
FFT(pa, loglen, n, -); for (int i = ; i < n; ++i) ans[i] = pa[i].re + 0.5;
for (int i = ; i<n; ++i) ans[i + ] += ans[i] / , ans[i] %= ; int pos = lena + lenb - ;
for (; pos> && ans[pos] <= ; --pos);
for (; pos >= ; --pos) printf("%d", ans[pos]);
puts("");
}
return ;
}

FFT之大数乘法的更多相关文章

  1. HDU1402:A * B Problem Plus(FFT与大数乘法)

    Calculate A * B. Input Each line will contain two integers A and B. Process to end of file. Note: th ...

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

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

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

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

  4. [hdu1402]大数乘法(FFT模板)

    题意:大数乘法 思路:FFT模板 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...

  5. HDU 1402 FFT 大数乘法

    $A * B$ FFT模板题,找到了一个看起来很清爽的模板 /** @Date : 2017-09-19 22:12:08 * @FileName: HDU 1402 FFT 大整数乘法.cpp * ...

  6. 51nod 1027大数乘法

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

  7. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  8. 用分治法实现大数乘法,加法,减法(java实现)

    大数乘法即多项式乘法问题,求A(x)与B(x)的乘积C(x),朴素解法的复杂度O(n^2),基本思想是把多项式A(x)与B(x)写成 A(x)=a*x^m+b B(x)=c*x^m+d 其中a,b,c ...

  9. HDOJ-1042 N!(大数乘法)

    http://acm.hdu.edu.cn/showproblem.php?pid=1042 题意清晰..简单明了开门见山的大数乘法.. 10000的阶乘有35000多位 数组有36000够了 # i ...

随机推荐

  1. #p-complete原来比np更难

    转载一下豆瓣的一个不知名的朋友的介绍: NP是指多项式时间内验证其解是否正确.比如: 我们给一个0-1背包的解,就可以在多项式时间内验证是否满足条件.至于是否能找到 满足条件的解,这在NP复杂度里没有 ...

  2. 200 from memory cache / from disk cache / 304 Not Modified 区别

    三者情况有什么区别和联系,什么情况下会发生200 from memory cache 或 200 from disk cache 或 304 Not Modified? 200 from memory ...

  3. js中字符串下划线转为驼峰

    function camelCase(string){ // Support: IE9-11+ return string.replace( /-([a-z])/g, function( all, l ...

  4. HDU I Hate It(线段树单节点更新,求区间最值)

    http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分 ...

  5. B-Boxes

    http://agc010.contest.atcoder.jp/tasks/agc010_b Problem Statement There are N boxes arranged in a ci ...

  6. SSD-tensorflow-2 evaluation

    测试就是用voc2007的test set来测试已经训练好的checkpoint的mAP,github上提供了三个已经训练好的model的checkpoint checkpoint 里面已有的300_ ...

  7. JS文字特效:彩色滚动变幻效果,只适合少量的文字。(过多对页面有影响)

    JS代码如下: 代码具体是在哪里的我不知道但是我的有道云上有.如有哪位朋友知道,还望联系下,添加出处. <div id="chakhsu"></div> & ...

  8. java 基于 bootstrap_datagrid 分页

    1.首先引入datagrid  js ,css $("#datagrid").bootstrap_datagrid({ url : "<%=path%>/us ...

  9. SweetAlert的入门

    在做后台管理系统,在用户交互这块(弹窗.提示相关),用了一款还不错的插件SweetAlert(一款原生js提示框,允许自定义,支持设置提示框标题.提示类型.确认取消按钮文本.点击后回调函数等等), 效 ...

  10. dd---复制文件并对原文件的内容进行转换和格式化处理

    dd命令用于复制文件并对原文件的内容进行转换和格式化处理.dd命令功能很强大的,对于一些比较底层的问题,使用dd命令往往可以得到出人意料的效果.用的比较多的还是用dd来备份裸设备.但是不推荐,如果需要 ...