整数最优分解问题
Sample Input
10
Sample Output
36
#include<stdio.h>
long b[160]={0};
long calculate(int m,int n)
{
long k;
long i,j,d=0,p=0,t;
b[0]=3;
for(i=1;i<m+n;i++)
{
if(i<m)t=3;
else t=2;
for(j=0;j<160;j++)
{
k=b[j]*t+d;
b[j]=k%10000000000;
d=k/10000000000;
}
if(d)b[j]=d;
}
for(i=159;i>=0;i--)
if(b[i]){p=i;break;}
return p;
}
void main()
{
long k1,k2;
long i,p,n;
scanf("%ld",&n);
if(n<4)printf("%ld",n-1);
else if(n==4)printf("4");
else
{
if(n%2==0)k1=n/6*2,k2=n%6/2;
else k1=(n-3)/6*2+1,k2=(n-3)%6/2;
p=calculate(k1,k2);
printf("%ld",b[p]);
for(i=p-1;i>=0;i--)
{
if(b[i]>999999999){printf("%ld",b[i]);continue;}
if(b[i]>99999999){printf("0%ld",b[i]);continue;}
if(b[i]>9999999){printf("00%ld",b[i]);continue;}
if(b[i]>999999){printf("000%ld",b[i]);continue;}
if(b[i]>99999){printf("0000%ld",b[i]);continue;}
if(b[i]>9999){printf("00000%ld",b[i]);continue;}
if(b[i]>999){printf("000000%ld",b[i]);continue;}
if(b[i]>99){printf("0000000%ld",b[i]);continue;}
if(b[i]>9){printf("00000000%ld",b[i]);continue;}
printf("000000000%ld",b[i]);
}
}
printf("\n");
}