UVa 10229 Modular Fibonacci

UVa 10229 Modular Fibonacci
Fibonacci数列一定会从F[0]、F[1]开始循环,这是JJ哥告诉我的……
于是,此题就很显然啦。
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
以下是我的代码:
#include  < vector >
#include 
< cstdio >
using   namespace  std;

int  n, m;
vector
< int >  r[ 27 ];

void  Init () {
    
for  ( m  =   1 ; m  <   20 ; m ++  ) {
        
int  mod  =  (  1   <<  m );
        
int  a  =   0 , b  =   1 , c  =   1   %  mod;
        r[m].push_back ( a );
        r[m].push_back ( b );
        r[m].push_back ( c );
        
while  ( b  !=   0   ||  c  !=   1  ) {
            a 
=  b; b  =  c; c  =  ( a  +  b )  %  mod;
            r[m].push_back ( c );
        }
        r[m].pop_back(); r[m].pop_back();
    }
}

int  main () {
#ifndef ONLINE_JUDGE
    freopen ( 
" data.in " " r " , stdin );
#endif
    Init ();
    
while  ( scanf (  " %d%d " & n,  & m )  ==   2  )
        
if  ( m ) printf (  " %d\n " , r[m][n % r[m].size()] );
        
else  printf (  " %d\n " 0  );
    
return   0 ;
}

你可能感兴趣的:(UVa 10229 Modular Fibonacci)