ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1013. K-based Numbers. Version 3

this is my answer
Posted by Sunnat 11 Jan 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
Posted by Ganesh R 2 Feb 2012 21:35
Can u pls explain me the concep of this problem. for wat we ve given the k value.?
Re: this is my answer
Posted by falicos 26 Feb 2012 13:52
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;