A * B Problem Plus

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22082    Accepted Submission(s): 5511

Problem Description

Calculate A * B.
 

Input

Each line will contain two integers A and B. Process to end of file.

Note: the length of each integer will not exceed 50000.

 

Output

For each case, output A * B in one line.
 

Sample Input

1
2
1000
2
 

Sample Output

2
2000
 

Author

DOOM III
 
 //2017-09-07
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <complex>
#include <cmath>
#define Complex complex<double> using namespace std; const double PI = acos(-1.0);
const int N = ; void fft(Complex y[], int n, int op){
for(int i = , j = n/; i < n-; i++){
if(i<j)swap(y[i], y[j]);
int k = n/;
while(j >= k){
j -= k;
k /= ;
}
if(j<k)j += k;
}
for(int h = ; h <= n; h <<= ){
Complex wn(cos(-op**PI/h), sin(-op**PI/h));
for(int j = ; j < n; j += h){
Complex w(, );
for(int k = j; k < j+h/; k++){
Complex u = y[k];
Complex t = w*y[k+h/];
y[k] = u+t;
y[k+h/] = u-t;
w = w*wn;
}
}
}
} char a[N], b[N];
Complex A[N<<], B[N<<];
int ans[N<<];
void poly_muilt(){
int n = , len1 = strlen(a), len2 = strlen(b);
while(n<len1* || n<len2*)n<<=;
for(int i = ; i < len1; i++)A[i] = a[len1-i-]-'';
for(int i = len1; i < n; i++)A[i] = ;
for(int i = ; i < len2; i++)B[i] = b[len2-i-]-'';
for(int i = len2; i < n; i++)B[i] = ;
fft(A, n, );
fft(B, n, );
for(int i = ; i < n; i++)
A[i] *= B[i];
fft(A, n, -);
for(int i = ; i < n; i++)
ans[i] = (int)(A[i].real()/n+0.5);
for(int i = ; i < n; i++){
ans[i+] += ans[i]/;
ans[i] %= ;
}
n = len1+len2-;
while(ans[n] <= && n > )n--;
for(int i = n; i >= ; i--)
printf("%c", ans[i]+'');
printf("\n");
} int main()
{
while(scanf("%s%s", a, b) != EOF){
poly_muilt();
} return ;
}

HDU1402(fft)的更多相关文章

  1. 快速傅里叶(FFT)的快速深度思考

    关于按时间抽取快速傅里叶(FFT)的快速理论深度思考 对于FFT基本理论参考维基百科或百度百科. 首先谈谈FFT的快速何来?大家都知道FFT是对DFT的改进变换而来,那么它究竟怎样改进,它改进的思想在 ...

  2. 【BZOJ3527】力(FFT)

    [BZOJ3527]力(FFT) 题面 Description 给出n个数qi,给出Fj的定义如下: \[Fj=\sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{ ...

  3. 【BZOJ4827】【HNOI2017】礼物(FFT)

    [BZOJ4827][HNOI2017]礼物(FFT) 题面 Description 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每 ...

  4. FFT/NTT总结+洛谷P3803 【模板】多项式乘法(FFT)(FFT/NTT)

    前言 众所周知,这两个东西都是用来算多项式乘法的. 对于这种常人思维难以理解的东西,就少些理解,多背板子吧! 因此只总结一下思路和代码,什么概念和推式子就靠巨佬们吧 推荐自为风月马前卒巨佬的概念和定理 ...

  5. 【BZOJ4503】两个串(FFT)

    [BZOJ4503]两个串(FFT) 题面 给定串\(S\),以及带通配符的串\(T\),询问\(T\)在\(S\)中出现了几次.并且输出对应的位置. \(|S|,|T|<=10^5\),字符集 ...

  6. 【BZOJ4259】残缺的字符串(FFT)

    [BZOJ4259]残缺的字符串(FFT) 题面 给定两个字符串\(|S|,|T|\),两个字符串中都带有通配符. 回答\(T\)在\(S\)中出现的次数. \(|T|,|S|<=300000\ ...

  7. 【51Nod1258】序列求和V4(FFT)

    [51Nod1258]序列求和V4(FFT) 题面 51Nod 多组数据,求: \[Ans=\sum_{i=1}^ni^k,n\le 10^{18},k\le50000\] 题解 预处理伯努利数,时间 ...

  8. 【CF528D】Fuzzy Search(FFT)

    [CF528D]Fuzzy Search(FFT) 题面 给定两个只含有\(A,T,G,C\)的\(DNA\)序列 定义一个字符\(c\)可以被匹配为:它对齐的字符,在距离\(K\)以内,存在一个字符 ...

  9. 【CF954I】Yet Another String Matching Problem(FFT)

    [CF954I]Yet Another String Matching Problem(FFT) 题面 给定两个字符串\(S,T\) 求\(S\)所有长度为\(|T|\)的子串与\(T\)的距离 两个 ...

随机推荐

  1. collections, time, queue的应用

    collections  (克来克深思) Counter from collections import Counter # 引入模块, 计数器 Counter(康特) s = 'sadfasdfas ...

  2. Spring Boot使用@Async实现异步调用:自定义线程池

    前面的章节中,我们介绍了使用@Async注解来实现异步调用,但是,对于这些异步执行的控制是我们保障自身应用健康的基本技能.本文我们就来学习一下,如果通过自定义线程池的方式来控制异步调用的并发. 定义线 ...

  3. powerDesigner 把name项添加到注释(comment)

    第一次写博客,分享一点经验吧,平时大家用powerDesigner的时候,pd是不会把name项默认添加到comment的,所以生成的数据库表里面也没有中文字段的注释. 我在网上查了一下.有解决方案了 ...

  4. POJ 2538

    #include<string> //#include #include<stdio.h> #include<iostream> using namespace s ...

  5. Android的几种弹出框

    项目效果图: 新建一个项目,结构图如下所示: activity_main.xml: <?xml version="1.0" encoding="utf-8" ...

  6. Executor框架(一)

    类继承关系 更详细的继承关系: ExecutorComplitionService类 在说Executor接口及实现类之前,先聊聊ExecutorComplitionService. 成员变量 pri ...

  7. 确保线程安全下使用Queue的Enqueue和Dequeue

    场景是这样,假设有一台设备会触发类型为Alarm的告警信号,并把信号添加到一个Queue结构中,每隔一段时间这个Queue会被遍历检查,其中的每个Alarm都会调用一个相应的处理方法.问题在于,检查机 ...

  8. JavaScript -- TextArea

    -----054-TextArea.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=&quo ...

  9. Element ui tree树形控件获取当前节点id和父节点id

    低版本Element ui tree树形控件获取当前节点id和父节点id的方法:点击查看 最新版本Element ui tree树形控件获取当前节点id和父节点id教程: 1.找到node_modul ...

  10. Maven <Profiles>定义不同环境的参数变量

    记录一下 https://blog.csdn.net/qq245282209/article/details/52192115