#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. WebView的坑[持续更新]

    返回错误的 innerHeight,如 240(WebView returns bad window.innerHeight) http://stackoverflow.com/questions/1 ...

  2. Gson解析List的一点小问题

    这阵子在使用gson解析时遇到了点小麻烦,因为一直用的fastjson,最近一个项目里使用的gson,需要解析list集合,查资料都是使用TypeToken解决,相对比较麻烦,下面为大伙推荐一种简便的 ...

  3. 加载等待loading

    自己写的一个小插件,还有很多需要完善... (function ($) {    $.fn.StartLoading = function (option) {        var defaultV ...

  4. PostgreSQL Replication之第九章 与pgpool一起工作(4)

    9.4 设置复制和负载均衡 要配置pgpool,我们可以简单地使用一个包含一种典型的配置信息的已经存在的样本文件,将它拷贝到我们的配置目录并修改之: $ cp /usr/local/etc/pgpoo ...

  5. Linux下通过rdesktop连接Windows远程桌面

    rdesktop是linux下支持Windows远程桌面连接的客户端程序,在linux系统下可通过它远程访问Windows桌面,支持多种版本.rdesktop是sourceforge下支持GPL协议的 ...

  6. AOC 电视机T3212M 进入 工厂模式方法,修改开机启动方式

    原启动方式: 通电,再按遥控 器上  “开机” 希望改成:  通电直接打开电视 方法: 1. 按遥控器上的 menu  1147  进入 工厂模式 2.  选择   7  General Settin ...

  7. Perl模块利用CPAN在线安装自动化

    需要解决2个问题: 1.  如何与CPAN交互:利用perl –MCPAN –e ‘install 模块’ 2.  如何安装指定的版本:作者/模块-版本.tar.gz How to install a ...

  8. 使用GitHub+Hexo建立个人网站,并绑定自己的域名(Ubuntu环境下)

    参考链接: youngzn.github.io     hexo官网     博客:从jekyll到hexo    hexo建站小结  全过程  简洁过程 使用GitHub+Hexo建立个人网站,并绑 ...

  9. OpenCV与Socket实现树莓派获取摄像头视频至电脑

    OpenCV能够为我们带来便捷的图像处理接口,但是其处理速度在一块树莓派上肯定是不尽如人意的.尤其当我们想要使用复杂的算法时,只能把算法托到服务器上才有可能.这里介绍了一种方法,实现树莓派传输Mat至 ...

  10. BZOJ 4034 线段树+DFS序

    思路: 先搞出来每个点的DFS序 (要有入栈和出栈两种状态的) 处理出来 线段树区间有多少入栈的和多少出栈的 加区间的时候就加(入-出)*wei 查前缀和 //By SiriusRen #includ ...