littlefrog @ 2019-08-29 09:41:49
// luogu-judger-enable-o2
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int a[999999];
long long x,len;
int main() {
ios::sync_with_stdio(0);
long long n;
cin>>n;
len = 1;
a[0] = 1;
for(int x = 1;x<=n;++x) {
for(int i = 0;i<len;++i) {
a[i]*=2;
}
for(int i = 0;i<len;i++) {
a[i+1]+=a[i]/10;
a[i]%=10;
}
while(a[len]) {
if(len>500) {
break;
}
a[len+1]+=a[len]/10;
a[len]%=10;
len++;
}
}
a[0]-=1;
for(int i = 0;i<len;++i) {
while(a[i]<0) {
a[i+1]--;
a[i]+=10;
}
}
while(len>1&&a[len-1]==0) {
len--;
}
cout<<(int)(n* log10(2))+1;
putchar('\n');
int p = 0;
for (int i = 499; i >= 0; i--) {
if(p==50) {
putchar('\n');
cout<<a[i];
p = 1;
}
else {
cout<<a[i];
p++;
}
}
return 0;
}
by Luban @ 2019-08-29 09:47:39
压位一下,10位压就可以过啦
当然某些大佬喜欢快速幂,然而我不喜欢
by Beyond616 @ 2019-08-29 10:07:01
@Taki 珂以将指数转换为二进制,设其有
乘幂次数等于
by Beyond616 @ 2019-08-29 10:07:39
@Taki 你这样做肯定超时
by boboyang @ 2019-08-29 10:09:52
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int r[500]={0},d[500]={0},t[500];
void m(int*a,int*b)
{
int i,k;
memset(t,0,sizeof(t));
for(i=0;i<500;i++) //高精度乘法
for(k=0;k<500;k++)
if(i+k<500)
t[i+k]+=a[i]*b[k];
else
break;
for(i=0;i<499;i++) //进位操作
{
t[i+1]+=t[i]/10;
a[i]=t[i]%10;
}
a[499]=t[499]%10;
}
main()
{
// freopen("mason.in","r",stdin);
// freopen("mason.out","w",stdout);
int i,n;
r[0]=1;
d[0]=2;
cin>>n;
cout<<int(n*log10(2)+1)<<endl; //数学推论,网上查的
while(n)
{
if(n&1) //有点像快速幂,将2^p分解
m(r,d);
m(d,d);
n>>=1;
}
r[0]--;
cout<<char(r[499]+48);
for(i=499;i>0;i--)
{
if(!(i%50))
cout<<endl;
cout<<char(r[i-1]+48);
}
return 0;
}
这是我写的洛谷c++AC代码
by Magallan_forever @ 2019-08-29 10:11:57
40行优化