#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. 怎么去除innerHTML获得内容中的标签?

    去掉innerHTML获得内容里面的标签: <body> <div id="d1"><p id="p1">hello wor ...

  2. file_get_contents 无法采集 https 网站

    <?php echo file_get_contents("https://www.baidu.com"); ?> 运行以上代码会报以下错误: 再运行一次去看看!

  3. ArcGIS api for javascript——地理处理任务-服务区域任务

    描述 本例展示了如何发送一些输入值到ArcGIS Server上的GIS模型并获得结果反馈给web应用.本例中,模型计算自在地图上单击点起始的驱动时间多边形. 例如,这个分析类型可用于想要知道多少人生 ...

  4. Android布局文件的载入过程分析:Activity.setContentView()源代码分析

    大家都知道在Activity的onCreate()中调用Activity.setContent()方法能够载入布局文件以设置该Activity的显示界面.本文将从setContentView()的源代 ...

  5. Android设置背景图片平铺

    以LinearLayout为例,它提供的background属性将会将背景图片拉伸,相当难看.其实我们仅仅需做少量的改动就能够实现web编程中css背景图片的效果.来试试吧. 创建反复的背景图片 在d ...

  6. Fragment的实际开发中总结(二)

    在实际项目的开发过程Fragment的情况越来越多.大家肯定须要遇到过Fragment被销毁重建的情况. 结合自己在项目开发的一点总结和学习开源项目的代码.继续分享自己对Fragment的一点总结. ...

  7. Android——4.2.2 文件系统文件夹分析

    近期公司要整android内部培训,分配给我写个培训文档.这里记录例如以下: 撰写不易,转载请注明出处:http://blog.csdn.net/jscese/article/details/4089 ...

  8. android中文网站

    Google Developers中国网站发布 用户评价:  / 55 差好  最后更新于 2016年12月09日 点击数:15209   我们很高兴地宣布,Google Developers 中国网 ...

  9. Ubuntu 13.04/CentOS 6.4 下C++开发时的相关设置

    Ubuntu 13.04/CentOS 6.4 下C++开发时的相关设置 一.基本设置 首先,为了可以使我们的c++ 可以找到 iostream类,std标准库,我们需要在C/C++ General- ...

  10. Aizu - 2564 Tree Reconstruction 并查集

    Aizu - 2564 Tree Reconstruction 题意:一个有向图,要使得能确定每一条边的权值,要求是每个点的入权和出权相等,问你最少需要确定多少条边 思路:这题好像有一个定理之类的,对 ...