PS：不是n=1的问题

# 2 条评论

• @ 2020-04-26 11:59:50

就是1的问题，我该了1后40点就通过了

• @ 2018-07-01 11:00:03
``````#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for (int i=1;i<=n;i++)
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define pos(x,y) (x+(y)*n)
const int N=100000+10;
const int inf=0x3f3f3f3f;
const ll mod=1000000007;
const double eps=1e-8;

int n;
struct bignum {
int len;
int a[1000];
int id;
bignum () {
len=0;
memset(a,0,sizeof a);
}
bignum operator*(bignum x) {
bignum res;
FOR(i,len) FOR(j,x.len) {
res.a[i+j-1]+=a[i]*x.a[j];
}
FOR(i,len+x.len-1) {
if (res.a[i]>9) {
res.a[i+1]+=res.a[i]/10;
res.a[i]%=10;
}
}
res.len=len+x.len-1;
if (res.a[res.len+1]) res.len++;
return res;
}
bignum operator=(bignum x) {
len=x.len;
FOR(i,len) a[i]=x.a[i];
}
bool operator==(bignum &x) {
if (len==x.len) {
FOR(i,len) {
if (a[i]!=x.a[i]) return 0;
}
return 1;
}
return 0;
}
};
bignum qpow(bignum a,int b) {
bignum res;
res.len=1,res.a[1]=1;
while (b) {
if (b&1) res=res*a;
a=a*a;
b>>=1;
}
return res;
}
void bmax(bignum &x,bignum y) {
if (x.len>y.len) return;
if (x.len<y.len) {
x=y;
return;
}
for (int i=x.len;i>=1;i--) {
if (x.a[i]<y.a[i]) {
x=y;
return;
} else if (x.a[i]>y.a[i]) break;
}
}
void print(bignum x) {
for (int i=x.len;i>=1;i--) cout<<x.a[i];
cout<<endl;
}
int main() {
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
cin>>n;
if (n==1) cout<<1<<endl;
bignum ans,two,three;
ans.len=1;
two.len=1,two.a[1]=2;
three.len=1,three.a[1]=3;
for (int x=0;x<=n;x++) {
int y=n-2*x;
if (y%3||y<0) continue;
y/=3;
bignum t=qpow(two,x);
bmax(ans,t*qpow(three,y));
}
print(ans);
return 0;
}
``````
• 1

ID
1033

5

(无)

3605

1161

32%

2