// fft模板 HDU 1402

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <math.h>
#include <memory.h>
#include <bits/stdc++.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const LL inf = 0x3f3f3f3f;
const LL MOD =100000000LL;
const int N = ;
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} const double PI = acos(-1.0);
//复数结构体
struct Complex{
double r,i;
Complex(double _r = 0.0,double _i = 0.0){
r = _r; i = _i;
}
Complex operator +(const Complex &b){
return Complex(r+b.r,i+b.i);
}
Complex operator -(const Complex &b){
return Complex(r-b.r,i-b.i);
}
Complex operator *(const Complex &b){
return Complex(r*b.r-i*b.i,r*b.i+i*b.r);
}
};
/*
* 进行FFT和IFFT前的反转变换。
* 位置i和 (i二进制反转后位置)互换
* len必须去2的幂
*/
void change(Complex y[],int len){
int i,j,k;
for(i = , j = len/;i < len-; i++){
if(i < j)swap(y[i],y[j]);
//交换互为小标反转的元素,i<j保证交换一次
//i做正常的+1,j左反转类型的+1,始终保持i和j是反转的
k = len/;
while( j >= k){
j -= k;
k /= ;
}
if(j < k) j += k;
}
}
/*
* 做FFT
* len必须为2^k形式,
* on==1时是DFT,on==-1时是IDFT
*/
void fft(Complex y[],int len,int on){
change(y,len);
for(int h = ; h <= len; h <<= ){
Complex wn(cos(-on**PI/h),sin(-on**PI/h));
for(int j = ;j < len;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;
}
}
}
if(on == -)
for(int i = ;i < len;i++)
y[i].r /= len;
} Complex a[N],b[N];
char s1[N/],s2[N/];
int ans[N];
int main(){
while(~scanf("%s%s",s1,s2)){
int len1=strlen(s1);
int len2=strlen(s2);
int l1=,l2=;
while((<<l1)<len1) l1++;
while((<<l2)<len2) l2++;
int len=(<<(max(l1,l2)+));
for(int i=;i<len;i++){
if(i<len1) a[i]=Complex(s1[len1-i-]-'',);
else a[i]=Complex(,);
if(i<len2) b[i]=Complex(s2[len2-i-]-'',);
else b[i]=Complex(,);
}
fft(a,len,);
fft(b,len,);
for(int i=;i<len;i++)
a[i]=a[i]*b[i];
fft(a,len,-);
for(int i=;i<len;i++)
ans[i]=(int)(a[i].r+0.5);
for(int i=;i<len-;i++){
ans[i+]+=ans[i]/;
ans[i]%=;
}
bool flag=false;
for(int i=len-;i>=;i--){
if(ans[i]) printf("%d",ans[i]),flag=true;
else if(flag||i==)printf("");
}
printf("\n");
}
return ;
}

fft模板 HDU 1402的更多相关文章

  1. HDU 1402 A * B Problem Plus (FFT模板题)

    FFT模板题,求A*B. 用次FFT模板需要注意的是,N应为2的幂次,不然二进制平摊反转置换会出现死循环. 取出结果值时注意精度,要加上eps才能A. #include <cstdio> ...

  2. HDU 1402 FFT 大数乘法

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

  3. hdu 1402 A * B Problem Plus FFT

    /* hdu 1402 A * B Problem Plus FFT 这是我的第二道FFT的题 第一题是完全照着别人的代码敲出来的,也不明白是什么意思 这个代码是在前一题的基础上改的 做完这个题,我才 ...

  4. A * B Problem Plus HDU - 1402 (FFT)

    A * B Problem Plus HDU - 1402 (FFT) Calculate A * B.  InputEach line will contain two integers A and ...

  5. hdu1402(大数a*b&fft模板)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1402 题意: 给出两个长度1e5以内的大数a, b, 输出 a * b. 思路: fft模板 详情参 ...

  6. 再写FFT模板

    没什么好说的,今天又考了FFT(虽然不用FFT也能过)但是确实有忘了怎么写FFT了,于是乎只有重新写一遍FFT模板练一下手了.第一部分普通FFT,第二部分数论FFT,记一下模数2^23*7*17+1 ...

  7. FFT模板(多项式乘法)

    FFT模板(多项式乘法) 标签: FFT 扯淡 一晚上都用来捣鼓这个东西了...... 这里贴一位神犇的博客,我认为讲的比较清楚了.(刚好适合我这种复数都没学的) http://blog.csdn.n ...

  8. P1919 【模板】A*B Problem升级版 /// FFT模板

    题目大意: 给定l,输入两个位数为l的数A B 输出两者的乘积 FFT讲解 这个讲解蛮好的 就是讲解里面贴的模板是错误的 struct cpx { double x,y; cpx(double _x= ...

  9. [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 ...

随机推荐

  1. Resource Archiver HDU - 3247 AC自动机+BFS+状压

    题意: 给出n个资源串,m个病毒串,现在要如何连接资源串使得不含病毒串(可以重叠,样例就是重叠的). 题解: 这题的套路和之前的很不同了,之前的AC自动机+DP的题目一般都是通过teir图去转移, 这 ...

  2. mysql commond record

    CREATE DATABASE IF NOT EXISTS codex_gm DEFAULT CHARACTER SET utf8; service mysqld stop screen -dmS m ...

  3. godaddy账号以及域名被盗找回经历以及网络信息安全的思考

    本案涉及到公司的一些机密信息,因此涉及到机密信息,我都将会用一些其他的代号进行替代.不影响读者理解本案.我会按照时间顺序讲述本案经过,是如何一步步找回godaddy账号的. 我供职的公司是一家网络科技 ...

  4. Educational Codeforces Round49

    A Palindromic Twist(字符串) 问每个字母必须向左或向右变成另一个字母,问能不能构成回文 #include <iostream> #include <string. ...

  5. 黑阀 adb 命令

    adb 命令 adb -d shell sh /data/data/me.piebridge.brevent/brevent.sh

  6. git sync tags with remote

    git 同步遠程標籤 在 .git/config的 [remote "origin"] 下加了 fetch = +refs/tags/*:refs/tags/* 最後就變成 [re ...

  7. win 10安装Nginx,php,mysql 小计

    一直没有尝试Nginx作为Web服务器,时常用的是apache,在Ubuntu下,输入一些安装命令就可以把LAMP环境比较轻松的搭建起来. 系统: windows 10 NT ,Nginx-1.14. ...

  8. It's a Mod, Mod, Mod, Mod World (类欧几里得模板题

    https://vjudge.net/contest/317000#problem/F #include <iostream> #include <cstdio> #inclu ...

  9. SG函数博弈——poj2311

    关于SG函数的博弈 首先定义必败态 x : SG[x]=0 设任意一个状态y,到所有y能到达的状态连一条边,令这些后继为z y : SG[y]=mex(SG[z]) SG[y]==0 : y就是必败态 ...

  10. 开源的DirectUI界面开发库DUILIB试用demo (Win32程序)

    Demo 第三版源码VC2005工程(附全部.h,ansi/unicode lib,dll),下载地址:http://goo.gl/c0L7Q   开源项目地址:http://code.google. ...