#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. mac terminal终端怎么退出python命令行

    >>>使用 quit(), exit(), 或者Command+d,或者Command+z退出命令行.

  2. Bootstrap modal.js 源码分析

    /* ======================================================================== * Bootstrap: modal.js v3 ...

  3. javascript面向对象编程,带你认识封装、继承和多态

    原文链接:点我 周末的时候深入的了解了下javascript的面向对象编程思想,收获颇丰,感觉对面向对象编程有了那么一丢丢的了解了~很开森 什么是面向对象编程 先上一张图,可以对面向对象有一个大致的了 ...

  4. 【Codeforces Round #239 (Div. 1) A】Triangle

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 最后的直角三角形可以通过平移,将直角顶点移动到坐标原点. 然后我们只要枚举另外两个点其中一个点的坐标就好了. x坐标的范围是[1.. ...

  5. “Vbox安装CentOS系统”之低级错误一例:版本号的选择

    日        期:2014年7月18日 错误描写叙述:虚拟机系统版本号选择错误,导致无法引导进入光盘安装 错误重演: 因为混淆了centos和rehat的版本号概念.错把centos作为一种新的版 ...

  6. 第五章,AsyncTask和ProgressBar的练习(Android)

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...

  7. 【v2.x OGE教程 17】事务处理

    游戏代码中常常有些逻辑须要处理.因此OGE引擎加入了一个IUpdateHandler的类. IUpdateHandler类是OGE引擎中使用频率很之高的组件之中的一个,其本身是一个接口.内部有onUp ...

  8. 利用opencv源代码和vs编程序训练分类器haartraining.cpp

    如需转载请注明本博网址:http://blog.csdn.net/ding977921830/article/details/47733363. 一  训练框架 训练人脸检測分类器须要三个步骤: (1 ...

  9. assert 的理解

    assert 可以实现如下功能: 保证参数之间的大小等约束关系: 函数执行过程中得到的中间结果是否符合预期: def gen_batch(batch_size, skip_window, num_sk ...

  10. 3.AngularJS-过滤器

    转自:https://www.cnblogs.com/best/p/6225621.html 二.过滤器 使用过滤器格式化数据,变换数据格式,在模板中使用一个插值变量.语法格式如下: {{ expre ...