2 条题解

  • 0
    @ 2025-7-8 9:29:34

    高精度乘法

    #include <iostream>
    #include <cmath>
    using namespace std;
    unsigned long long a[510] = {0, 1}, t;
    int p;
    int main()
    {
        cin >> p;
        cout << (int)(p * log10(2)) + 1 << endl;
        for (; p >= 0; p -= 60)
        {
            t = 0;
            for (int j = 1; j <= 500; j++)
            {
                if (p >= 60) a[j] <<= 60;
                else a[j] <<= p;
                a[j] += t;
                t = a[j] / 10;
                a[j] %= 10;
            }
        }
        a[1] -= 1;
        for (int i = 500; i >= 1; i--) 
        {
            cout << (char)('0' + a[i]);
            if (i % 50 == 1) cout << endl;
        }
        return 0;
    }
    
    • 0
      @ 2022-7-5 8:10:39

      高精+快速幂即可。

      位数是 log102n=n×log102\log_{10} 2^n=n\times\log_{10} 2

      #include <bits/stdc++.h>
      using namespace std;
      const int N = 1005, k = 500;
      int n;
      struct fig {
      	int a[N];
      	void print() {
      		a[1] -= 1;
      		for (int i = 1; i <= k; i ++) {
      			cout << a[k - i + 1];
      			if (i % 50 == 0)
      				cout << '\n';
      		}
      		cout << '\n';
      	}
      	fig operator *= (fig x) {
      		fig s = *this;
      		memset(a, 0, sizeof a);
      		for (int i = 1; i <= k; i ++) {
      			fig t = s;
      			for (int j = k; j >= 1; j --) {
      				t.a[j] *= x.a[i];
      				t.a[j + 1] += t.a[j] / 10, t.a[j] %= 10;
      			}
      			for (int j = i; j <= k; j ++) {
      				a[j] += t.a[j - i + 1];
      				if (a[j] > 9) a[j + 1] += a[j] / 10, a[j] %= 10;
      			}
      		}
      		return *this;
      	}
      	fig(int x) {
      		a[1] = x;
      	}
      } bas(2), ans(1);
      int real() {
      	int res = 0;
      	for (int i = k; !ans.a[i]; i --)
      		res ++;
      	return k - res;
      }
      int main() {
      //	freopen("mason.in", "r", stdin);
      //	freopen("mason.out", "w", stdout);
      	cin >> n;
      	cout << int(n * log10(2) + 1) << '\n';
      	while(n) {
      		if (n & 1) ans *= bas;
      		bas *= bas;
      		n >>= 1;
      	}
      	ans.print();
      	return 0;
      }
      
      • 1

      信息

      ID
      110
      时间
      1000ms
      内存
      256MiB
      难度
      6
      标签
      (无)
      递交数
      22
      已通过
      12
      上传者