/*
Copyright 2011 Marek "p2004a" Rusinowski
nth element of Fibonacci sequence (linear)
*/
#include <cstdio>
int fib( int n, int c) {
int a = 1 , b = 1 ;
for ( int i = 2 ; i < n; ++ i) {
int tmp = b;
b = ( a + b) % c;
a = tmp;
}
return b;
}
int main( ) {
int a, c;
scanf ( "%d %d" , & a, & c) ;
printf ( "%d\n " , fib( a, c) ) ;
return 0 ;
}
LyoKICBDb3B5cmlnaHQgMjAxMSBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgbnRoIGVsZW1lbnQgb2YgRmlib25hY2NpIHNlcXVlbmNlIChsaW5lYXIpCiovCiNpbmNsdWRlIDxjc3RkaW8+CgppbnQgZmliKGludCBuLCBpbnQgYykgewogIGludCBhID0gMSwgYiA9IDE7CiAgZm9yIChpbnQgaSA9IDI7IGkgPCBuOyArK2kpIHsKICAgIGludCB0bXAgPSBiOwogICAgYiA9IChhICsgYikgJSBjOwogICAgYSA9IHRtcDsKICB9CiAgcmV0dXJuIGI7Cn0KCmludCBtYWluKCkgewogIGludCBhLCBjOwogIHNjYW5mKCIlZCAlZCIsICZhLCAmYyk7CiAgcHJpbnRmKCIlZFxuIiwgZmliKGEsIGMpKTsKICByZXR1cm4gMDsKfQo=
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout