妈妈我终于会\(A*B\ problem\)啦~~

题目大意:

给你两个正整数 \(a,b\),求\(a*b\)

其中\(a,b\le 10^{1000000}\)

我们只要把多项式\(A(x)=\sum\limits_{i=0}^{n-1}a_i*x_i\)的\(x\)看作\(10\)就好啦~

注意输入顺序和多项式顺序相反,记得反过来

跑\(fft\),再高精乘求出每一位的系数

#include<bits/stdc++.h>
using namespace std;
namespace red{
#define int long long
#define eps (1e-8)
inline int read()
{
int x=0;char ch,f=1;
for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
if(ch=='-') f=0,ch=getchar();
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
}
const int N=5e6+10;
const double pi=acos(-1.0);
int n,m;
char aa[1000010],bb[1000010];
int limit=1,len;
int pos[N],ret[N];
struct complex
{
double x,y;
complex(double tx=0,double ty=0){x=tx,y=ty;}
inline complex operator + (const complex t) const
{
return complex(x+t.x,y+t.y);
}
inline complex operator - (const complex t) const
{
return complex(x-t.x,y-t.y);
}
inline complex operator * (const complex t) const
{
return complex(x*t.x-y*t.y,x*t.y+y*t.x);
}
}a[N],b[N];
inline void fft(complex *a,int inv)
{
for(int i=0;i<limit;++i)
if(i<pos[i]) swap(a[i],a[pos[i]]);
for(int mid=1;mid<limit;mid<<=1)
{
complex Wn(cos(pi/mid),inv*sin(pi/mid));
for(int r=mid<<1,j=0;j<limit;j+=r)
{
complex w(1,0);
for(int k=0;k<mid;++k,w=w*Wn)
{
complex x=a[j+k],y=w*a[j+k+mid];
a[j+k]=x+y;
a[j+k+mid]=x-y;
}
}
}
}
inline void main()
{
scanf("%s%s",aa,bb);
n=strlen(aa),m=strlen(bb);
for(int i=n-1;~i;--i) a[n-1-i].x=aa[i]-'0';
for(int i=m-1;~i;--i) b[m-1-i].x=bb[i]-'0';
while(limit<n+m) limit<<=1,++len;
for(int i=0;i<limit;++i) pos[i]=(pos[i>>1]>>1)|((i&1)<<(len-1));
fft(a,1);
fft(b,1);
for(int i=0;i<=limit;++i) a[i]=a[i]*b[i];
fft(a,-1); for(int i=0;i<=limit;++i)
{
ret[i]+=a[i].x/limit+0.5;
if(ret[i]>=10)
{
ret[i+1]+=ret[i]/10;
ret[i]%=10;
limit+=(i==limit);
}
}
while(!ret[limit]&&limit) --limit;
++limit;
while(--limit>=0) putchar('0'+ret[limit]);
}
}
signed main()
{
red::main();
return 0;
}

洛谷 P1919 A*B Problem升级版的更多相关文章

  1. 洛谷P1919 A*B problem 快速傅里叶变换模板 [FFT]

    题目传送门 A*B problem 题目描述 给出两个n位10进制整数x和y,你需要计算x*y. 输入输出格式 输入格式: 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数 ...

  2. 洛谷P1919 【模板】A*B Problem升级版 题解(FFT的第一次实战)

    洛谷P1919 [模板]A*B Problem升级版(FFT快速傅里叶) 刚学了FFT,我们来刷一道模板题. 题目描述 给定两个长度为 n 的两个十进制数,求它们的乘积. n<=100000 如 ...

  3. 洛谷1001 A+B Problem

    洛谷1001 A+B Problem 本题地址:http://www.luogu.org/problem/show?pid=1001 题目描述 输入两个整数a,b,输出它们的和(|a|,|b|< ...

  4. 洛谷P1553 数字翻转(升级版)

    题目链接 https://www.luogu.org/problemnew/show/P1553 题目描述 给定一个数,请将该数各个位上数字反转得到一个新数. 这次与NOIp2011普及组第一题不同的 ...

  5. 洛谷1303 A*B Problem 解题报告

    洛谷1303 A*B Problem 本题地址:http://www.luogu.org/problem/show?pid=1303 题目描述 求两数的积. 输入输出格式 输入格式: 两个数 输出格式 ...

  6. 洛谷1601 A+B Problem(高精) 解题报告

    洛谷1601 A+B Problem(高精) 本题地址:http://www.luogu.org/problem/show?pid=1601 题目背景 无 题目描述 高精度加法,x相当于a+b pro ...

  7. 洛谷P1865 A % B Problem

    1.洛谷P1865 A % B Problem 题目背景 题目名称是吸引你点进来的 实际上该题还是很水的 题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行 ...

  8. 洛谷P1919 【模板】A*B Problem升级版(FFT快速傅里叶)

    题目描述 给出两个n位10进制整数x和y,你需要计算x*y. 输入输出格式 输入格式: 第一行一个正整数n. 第二行描述一个位数为n的正整数x. 第三行描述一个位数为n的正整数y. 输出格式: 输出一 ...

  9. 洛谷 P1001 A+B Problem

    题目描述 输入两个整数a,b,输出它们的和(|a|,|b|<=10^9). 注意 1.pascal使用integer会爆掉哦! 2.有负数哦! 3.c/c++的main函数必须是int类型,而且 ...

随机推荐

  1. 项目倒入maven 遇到的问题只有 main 了

    归根结底是倒入错了: (1)首先  view->Toolbar; (2) 点击 File==>project structure 然后:在 project settings中点击 modu ...

  2. LeetCode 160: 相交链表 Intersection of Two Linked Lists

    爱写Bug(ID:iCodeBugs) 编写一个程序,找到两个单链表相交的起始节点. Write a program to find the node at which the intersectio ...

  3. LeetCode 203:移除链表元素 Remove LinkedList Elements

    删除链表中等于给定值 val 的所有节点. Remove all elements from a linked list of integers that have value val. 示例: 输入 ...

  4. IIS_CVE-2017-7269 IIS6.0远程代码执行漏洞复现

    CVE-2017-7269 IIS6.0远程代码执行漏洞复现 一.漏洞描述 IIS 6.0默认不开启WebDAV,一旦开启了WebDAV,安装了IIS6.0的服务器将可能受到该漏洞的威胁. 二.影响版 ...

  5. AOP方法拦截获取参数上的注解

    https://www.jianshu.com/p/f5c7417a75f9 获取参数注解 在spring aop中,无论是前置通知的参数JoinPoint,还是环绕通知的参数ProceedingJo ...

  6. SQL Server中INSERT EXEC语句不能嵌套使用(转载)

    问: I have three stored procedures Sp1, Sp2 and Sp3.The first one (Sp1) will execute the second one ( ...

  7. Mvc 入门及基础了解

    用于表示一种软件架构模式.它把软件系统分为三个基本部分 _模型(Model), _视图(View) _和控制器(Controller). 其中主要代码是 路由 配置默认的路径: 默认配置 是 Home ...

  8. laravel he stream or file "..laravel-2019-02-14.log" could not be opened: failed to open stream: Permission denied

    错误:The stream or file "/var/www/jianshu/storage/logs/laravel-2019-02-14.log" could not be ...

  9. Java生鲜电商平台-一次代码重构的实战案例

    Java生鲜电商平台-一次代码重构的实战案例 说明,Java开源生鲜电商平台-一次代码重构的实战案例,根据实际的例子,分析出重构与抽象,使代码更加的健壮与高效. 1.业务说明 系统原先已有登录功能,我 ...

  10. [Tomcat源码分析] Eclipse中搭建Apache Tomcat源码调试环境

    网上很多文章都推荐使用Ant下载编译,但本地实践中屡屡失败,无法下载. 后来参考 https://blog.csdn.net/xiongyouqiang/article/details/7894107 ...