宣传自己写的高精
查看原帖
宣传自己写的高精
53022
银杉水杉秃杉楼主2021/9/2 20:55

之前发错版块了

自己写的高精,打了一下午,大家支持一下呗OwO

复杂度可能有些高(我太菜了,FFT,NTT啥的不会),应该能用吧

博客:在这里

目前只支持正整数,如果有大佬愿意帮忙添加点东西(比如支持负整数),蒟蒻感激不尽。

大家要用的话,大家根据题目要求修改数组大小,因为可能要爆。(别忘了多开几位)

不想点链接,看这儿(有点影响视觉效果)

struct bigint
{
    int n, a[10010];
    bool f;
    bigint()
    {
        clear();
    }
    void clear()
    {
        n = 1, f = 1;
        memset(a, 0, sizeof(a));
    }
    void read()
    {
        cin >> n;
        for (int i = n; i >= 1; i--)
            cin >> a[i];
    }
    void write()
    {
        if (!f)
            cout << '-';
        for (int i = n; i >= 1; i--)
            cout << a[i];
        cout << endl;
    }
    void operator=(int x)
    {
        clear();
        if (x == 0)
            return;
        if (x < 0)
            x = -x, f = 0;
        n = 0;
        while (x)
        {
            a[++n] = x % 10;
            x /= 10;
        }
    }
    void operator=(string x)
    {
        clear();
        int st = 0;
        if (x[0] == '-')
            f = 0, st++;
        for (int i = st; i < x.size(); i++)
            a[++n] = x[i] - '0';
    }
    void operator=(bigint x)
    {
        clear();
        n = x.n;
        f = x.f;
        for (int i = 1; i <= n; i++)
            a[i] = x.a[i];
    }
    bool operator==(bigint x)
    {
        if (n != x.n)
            return 0;
        for (int i = n; i >= 1; i++)
            if (a[i] != x.a[i])
                return 0;
        return 1;
    }
    bool operator!=(bigint x)
    {
        return !operator==(x);
    }
    bool operator<(bigint x)
    {
        if (n == x.n)
            for (int i = n; i >= 1; i--)
                if (a[i] != x.a[i])
                    return a[i] < x.a[i];
        return n < x.n;
    }
    bool operator>(bigint x)
    {
        if (n == x.n)
            for (int i = n; i >= 1; i--)
                if (a[i] != x.a[i])
                    return a[i] > x.a[i];
        return n > x.n;
    }
    bool operator<=(bigint x)
    {
        return !operator>(x);
    }
    bool operator>=(bigint x)
    {
        return !operator<(x);
    }
    bool operator!()
    {
        if (n != 1)
            return 0;
        return a[1] == 0;
    }
    bool operator==(int x)
    {
        bigint y;
        y = x;
        return operator==(y);
    }
    bool operator!=(int x)
    {
        bigint y;
        y = x;
        return operator!=(y);
    }
    bool operator<(int x)
    {
        bigint y;
        y = x;
        return operator<(y);
    }
    bool operator>(int x)
    {
        bigint y;
        y = x;
        return operator>(y);
    }
    bool operator<=(int x)
    {
        bigint y;
        y = x;
        return operator<=(y);
    }
    bool operator>=(int x)
    {
        bigint y;
        y = x;
        return operator>=(y);
    }
    bigint operator+(bigint x)
    {
        bigint y;
        y.n = max(n, x.n);
        int s = 0;
        for (int i = 1; i <= y.n; i++)
        {
            s += a[i] + x.a[i];
            y.a[i] = s % 10;
            s /= 10;
        }
        while (s)
        {
            y.a[++y.n] += s % 10;
            s /= 10;
        }
        return y;
    }
    bigint operator+(int x)
    {
        bigint y;
        y = x;
        return operator+(y);
    }
    bigint operator-(bigint x)
    {
        bigint y, z = *this;
        if (z < x)
            y.f = 0, swap(z, x);
        y.n = z.n;
        for (int i = 1; i <= y.n; i++)
        {
            if (z.a[i] < x.a[i])
            {
                z.a[i + 1]--;
                z.a[i] += 10;
            }
            y.a[i] = z.a[i] - x.a[i];
        }
        while (y.a[y.n] == 0 && y.n > 1)
            y.n--;
        return y;
    }
    bigint operator-(int x)
    {
        bigint y;
        y = x;
        return operator-(y);
    }
    bigint operator*(bigint x)
    {
        bigint y;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= x.n; j++)
                y.a[i + j - 1] += a[i] * x.a[j];
        y.n = n + x.n;
        for (int i = 1; i < y.n; i++)
            if (y.a[i] >= 10)
            {
                y.a[i + 1] += y.a[i] / 10;
                y.a[i] %= 10;
            }
        while (y.a[y.n] == 0 && y.n > 1)
            y.n--;
        return y;
    }
    bigint operator*(int x)
    {
        bigint y;
        y = x;
        return operator*(y);
    }
    bigint operator/(bigint x)
    {
        bigint y, z = *this;
        if (x == y)
            return x;
        y.n = z.n - x.n + 1;
        for (int i = y.n; i >= 1; i--)
        {
            bigint t = x << (i - 1);
            while (z >= t)
            {
                y.a[i]++;
                z -= t;
            }
        }
        while (y.a[y.n] == 0 && y.n > 1)
            y.n--;
        return y;
    }
    bigint operator/(int x)
    {
        bigint y;
        y = x;
        return operator/(y);
    }
    bigint operator%(bigint x)
    {
        bigint z = *this;
        return z - z / x * x;
    }
    bigint operator%(int x)
    {
        bigint y;
        y = x;
        return operator%(y);
    }
    bigint operator<<(int l)
    {
        bigint x;
        for (int i = 1; i <= n; i++)
            x.a[i + l] = a[i];
        x.n = n + l;
        return x;
    }
    bigint operator>>(int l)
    {
        bigint x;
        x.n = n - l;
        for (int i = 1; i <= x.n; i++)
            x.a[i] = a[i + l];
        return x;
    }
    void operator+=(bigint x)
    {
        bigint z = *this;
        *this = z + x;
    }
    void operator-=(bigint x)
    {
        bigint z = *this;
        *this = z - x;
    }
    void operator*=(bigint x)
    {
        bigint z = *this;
        *this = z * x;
    }
    void operator/=(bigint x)
    {
        bigint z = *this;
        *this = z / x;
    }
    void operator%=(bigint x)
    {
        bigint z = *this;
        *this = z % x;
    }
    void operator+=(int x)
    {
        bigint z = *this;
        *this = z + x;
    }
    void operator-=(int x)
    {
        bigint z = *this;
        *this = z - x;
    }
    void operator*=(int x)
    {
        bigint z = *this;
        *this = z * x;
    }
    void operator/=(int x)
    {
        bigint z = *this;
        *this = z / x;
    }
    void operator%=(int x)
    {
        bigint z = *this;
        *this = z % x;
    }
};
2021/9/2 20:55
加载中...