fork(22) download
  1. #include<stdio.h>
  2. void
  3. matrix_mul(long long int fibo[2][2],long long int whatever[2][2],long long int temp[2][2])
  4. {
  5. int i,j,k;
  6. int sum=0;
  7. for(k=0;k<2;k++)
  8. {
  9. for(i=0;i<2;i++)
  10. {
  11. sum=0;
  12. for(j=0;j<2;j++)
  13. {
  14. sum+=fibo[k][j]*whatever[j][i];
  15. }
  16. temp[k][i]=sum;
  17. }
  18. }
  19. }
  20. int
  21. main()
  22. {
  23. long long int fibo[2][2]={{1,1},
  24. {1,0}};
  25. long long int previous[2][2]={{1,1},
  26. {1,0}};
  27. long long int temp[2][2]={{0,0},
  28. {0,0}};
  29. int n;
  30. int i,j;
  31. scanf("%d",&n);
  32. n=n-1;
  33. while(n)
  34. {
  35.  
  36. if(n%2==1)
  37. {
  38. matrix_mul(fibo,previous,temp);
  39. for(i=0;i<2;i++)
  40. {
  41. for(j=0;j<2;j++)
  42. {
  43. previous[i][j]=temp[i][j];
  44. }
  45. }
  46. }
  47. matrix_mul(fibo,fibo,temp);
  48. for(i=0;i<2;i++)
  49. {
  50. for(j=0;j<2;j++)
  51. {
  52. fibo[i][j]=temp[i][j];
  53. }
  54. }
  55. n=n/2;
  56. }
  57. printf("%lld",previous[0][0]);
  58.  
  59. return 0;
  60. }
  61.  
  62.  
  63.  
stdin
5
compilation info
prog.c: In function ‘main’:
prog.c:31: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
stdout
8