|
|
вернуться в форумthis is my answer Послано Sunnat 11 янв 2012 18:54 #include<cstdio> int main() { short a[2000]={0},b[2000]={0},c[2000]={0}; short g,i,j,m=1; int n,k; scanf("%i %i",&n,&k); a[0]=1; b[0]=k-1; for(i=2;i<=n;i++) { g=0; for(j=0;j<m;j++) { c[j]=a[j]+b[j]; c[j]=c[j]*(k-1)+g; (c[j]>9)?g=c[j]/10,c[j]=c[j]%10:g=0; a[j]=b[j]; b[j]=c[j]; } (g!=0)?b[m++]=g:b[m]=g; } for(j=m-1;j>=0;j--)printf("%d",b[j]); return 0; } Request Can u pls explain me the concep of this problem. for wat we ve given the k value.? Re: this is my answer congratulation for excellent code. The only suggestion. May be (g!=0)?b[m++]=g:b[m]=g; better to replace by if(g) b[m++]=g; |
|
|