AcWing 416. 麦森数
原题链接
简单
作者:
Value
,
2020-09-06 11:52:19
,
所有人可见
,
阅读 291
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 500;
int res[N], base[N], other[N];
void mul(int c[], int a[], int b[]){
memset(other, 0, sizeof other);
for(int i = 0; i < N; i ++ ){
for(int j = 0; i + j < N; j ++ ){
other[i + j] += a[i] * b[j];
}
}
for(int i = 0, t = 0; i < N; i ++ ){
t += other[i];
c[i] = t % 10;
t /= 10;
}
}
void qmi(int k){
res[0] = 1;
base[0] = 2;
while(k){
if(k & 1) mul(res, res, base);
mul(base, base, base);
k >>= 1;
}
res[0] -- ;
}
int main(){
int n; cin >> n;
cout << int(n * log10(2)) + 1 << endl;
qmi(n);
for(int i = 0, k = N - 1; i < 10; i ++ ){
for(int j = 0; j < 50; j ++ ) cout << res[k -- ];
cout << endl;
}
return 0;
}