题解
2023-08-25 11:17:16
发布于:广东
46阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
vector<int> mul(vector<int> &A, vector<int> &B) {
int i, j;
vector<int> C(A.size() + B.size());
for (i = 0; i < A.size(); i++) {
for (j = 0; j < B.size(); j++) {
C[i + j] += A[i] * B[j];
}
}
int temp = 0;
for (i = 0; i < C.size(); i++) {
temp += C[i];
C[i] = temp % 10;
temp /= 10;
}
while (C.size() < 500) C.push_back(0);
if (C.size() > 500) {
C.resize(500);
}
return C;
}
vector<int> poww(int b) {
vector<int> A, B;
string a = "1";
string base = "2";
int i;
for (i = a.size() - 1; i >= 0; i--) A.push_back(a[i] - '0');
for (i = base.size() - 1; i >= 0; i--) B.push_back(base[i] - '0');
while (b != 0) {
if (b & 1 != 0) A = mul(A, B);
B = mul(B, B);
b >>= 1;
}
return A;
}
int main() {
vector<int> C;
int P, N, i;
cin >> P;
N = P * log10(2) + 1;
cout << N << endl;
C = poww(P);
C[0]--;
for (i = C.size() - 1; i >= 0; i--) {
cout << C[i];
}
return 0;
}
太经典的快速幂了
这里空空如也
有帮助,赞一个