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 1133. Fibonacci Sequence

WHY I GET WA ON TEST 10..
Posted by Ghost 21 Nov 2007 07:02
IF YOU KNOW , CAN U CONTACT WITH ME ..
MY EMAIL IS ZELIN.HE@GMAIL.COM
THX..
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
long double f1[2001],f2[2001];
int main()
{
    int x , y , fx , fy , n ;
    double fn;
    scanf("%d%d%d%d%d",&x,&fx,&y,&fy,&n);
    f1[0] = 1 ; f1[1] = 0 ;
    f2[0] = 0 ; f2[1] = 1 ;
    if ( x > y )
    {
     int  tmp = x ;
       x = y ;
       y = tmp ;
       tmp = fx;
       fx = fy;
       fy = tmp;
    }
    int k ;
    int i;
    for ( i=x+2; i <= y ; i ++ )
    {
      if ( x < 0 ) k = -x + i;
      else k = i - x;
      f1[k] = f1[k-1]+f1[k-2];
      f2[k] = f2[k-1]+f2[k-2];
    }

    long double b = ceil(fy-f1[y-x]*fx)/(f2[y-x]);
    long double a = fx;
    long double c;
 if ( x+2 <= n )
 {
    for ( i = x+2 ; i <= n ; i ++ )
    {
        c = a + b ;
        a = b ; b = c ;
    }
    printf("%.0llf\n",c);
 }
 else
 {
   if (x == n ) printf("%.0llf\n",a);
    else if ( n == x + 1 ) printf("%.0llf\n",b);
       else
       {
          for (i = x ; i > n ; i -- )
           {
              c = b - a ;
              b = a ; a = c;
           }
          printf("%.0llf\n",c);
       }

 }

    system("PAUSE");
    return 0;
}
Re: WHY I GET WA ON TEST 10..
Posted by Shahriar Nirjon 7 May 2009 06:51
I did similarly in C++ and was getting WA on #10. Later, I wrote the same solution in Java (with BigInteger) and worked.