Advertisement
a53

Walker

a53
Feb 5th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define M 666013
  3. using namespace std;
  4. unsigned long long n,k;
  5. long long a[3][3],b[3][3],aux[3][3];
  6.  
  7. void inmulteste1()
  8. {
  9. for(int i=1;i<=2;++i)
  10. {
  11. for(int j=1;j<=2;++j)
  12. {
  13. aux[i][j]=0;
  14. for(int k=1;k<=2;++k)
  15. aux[i][j]=(aux[i][j]+1LL*b[i][k]*a[k][j])%M;
  16. }
  17. }
  18. for(int i=1;i<=2;++i)
  19. for(int j=1;j<=2;++j)
  20. b[i][j]=aux[i][j];
  21. }
  22.  
  23. void inmulteste2()
  24. {
  25. for(int i=1;i<=2;++i)
  26. {
  27. for(int j=1;j<=2;++j)
  28. {
  29. aux[i][j]=0;
  30. for(int k=1;k<=2;++k)
  31. aux[i][j]=(aux[i][j]+1LL*a[i][k]*a[k][j])%M;
  32. }
  33. }
  34. for(int i=1;i<=2;++i)
  35. for(int j=1;j<=2;++j)
  36. a[i][j]=aux[i][j];
  37. }
  38.  
  39. void lgpow(long long exponent)
  40. {
  41. while(exponent)
  42. {
  43. if(exponent&1)
  44. inmulteste1();
  45. inmulteste2();
  46. exponent>>=1;
  47. }
  48. }
  49.  
  50. int main()
  51. {
  52. cin.tie(0)->sync_with_stdio(0);
  53. cin.tie(0);
  54. cout.tie(0);
  55. cin>>n>>k;
  56. a[1][1]=0,a[1][2]=n-1,a[2][1]=1,a[2][2]=n-2;
  57. b[1][1]=1,b[2][2]=1;
  58. lgpow(k);
  59. cout<<b[1][1];
  60. return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement