creativewang

code1

May 29th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. /*
  2.     HDU 1005 number sequence
  3. */
  4.  
  5. #include<stdio.h>
  6. #define SEQ_LEN 100000
  7.  
  8. int main(void)
  9. {
  10.     long n;
  11.     int a,b,len,seq[SEQ_LEN];
  12.    
  13.     while(scanf("%d%d%ld",&a,&b,&n),a||b||n)
  14.     {
  15.         len=3;
  16.         seq[1]=seq[2]=1;
  17.         seq[3]=(a*seq[2]+b*seq[1])%7;
  18.         while((seq[len]!=1||seq[len-1]!=1)&&len<SEQ_LEN-1)
  19.             len++,seq[len]=(a*seq[len-1]+b*seq[len-2])%7;
  20.         seq[0]=seq[len-2];
  21.         printf("%d\n",seq[n%(len-2)]);
  22.     }
  23.  
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment