fork download
  1. /*
  2.   Copyright 2011 Marek "p2004a" Rusinowski
  3.   nth element of Fibonacci sequence (linear)
  4. */
  5. #include <cstdio>
  6.  
  7. int fib(int n, int c) {
  8. int a = 1, b = 1;
  9. for (int i = 2; i < n; ++i) {
  10. int tmp = b;
  11. b = (a + b) % c;
  12. a = tmp;
  13. }
  14. return b;
  15. }
  16.  
  17. int main() {
  18. int a, c;
  19. scanf("%d %d", &a, &c);
  20. printf("%d\n", fib(a, c));
  21. return 0;
  22. }
  23.  
stdin
19 10000000
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
4181