刘汝佳的《算法竞赛入门经典》中给出过大整数类的代码,但其只实现了输入输出、加减法和比较的功能,并未实现乘法。本文在他的代码的基础上,采用FFT算法实现了高精度乘法运算。
FFT算法讲解:
https://blog.youkuaiyun.com/ripped/article/details/70241716
https://www.cnblogs.com/DreamlessDreams/p/8697931.html
https://blog.youkuaiyun.com/enjoy_pascal/article/details/81478582
不熟悉FFT算法的话建议同时浏览对照学习。第一个博客在文章开头所分享的博客给出了较为详细的数学证明,后两个博客对FFT算法做了较为全面的总结,各有千秋。
C++代码如下:
#include <iostream>
#include <algorithm>
#include <complex>
#include <string>
#include <vector>
#define cp complex<double>
const double pi = 3.1415926;
const int maxn = 257;
using namespace std;
class BigInteger
{
private:
static const int BASE = 100000000;
static const int WIDTH = 8;
void recursion_fft(cp *a, int n, int inv) const
{

最低0.47元/天 解锁文章
662

被折叠的 条评论
为什么被折叠?



