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 1012. K-based Numbers. Version 2

AC with 439 KB!!!! 0.062 sec!!!
Posted by MAT 7 Nov 2007 01:34
I've got 1013    C++    Accepted 0.062    439 КБ
with a help of such construction:
    huge f[5];
    int i,n,k;
    char c[2];
    cin>>n>>k;
    cin.getline(c,1);
    f[0].d[0]=1;
    f[0].len=1;
    f[1].len=1;
    f[1].d[0]=k-1;
    for(i=2;i<=n;i++)
    {
        f[i%5]=(f[(i-1)%5]+f[(i-2)%5])*(k-1);
    }
    f[n%5].output();
    return 0;
this is int main() code
Here huge f[5] is an array of long arithmetic classes in which i used overloaded operators "+" and "*"
This code REALLY works
It is memory-economical code :-)

Edited by author 07.11.2007 01:35

Edited by author 07.11.2007 01:38
Re: AC with 439 KB!!!! 0.062 sec!!!
Posted by Alexander J. Villalba G. 27 Mar 2008 20:32
Thanks you !!!