Advertisement
a53

Pandemia

a53
May 1st, 2021 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MOD=10000007;
  4.  
  5. ifstream fin("pandemia.in");
  6. ofstream fout("pandemia.out");
  7.  
  8. /// Struct ce retine o matrice 3x3
  9. struct Mat
  10. {
  11. long long mat[3][3];
  12. };
  13.  
  14. /// Elementul neutru la înmultirea matricelor 3x3
  15. Mat nullMat, Cmat, fMat, Put, initMat;
  16.  
  17. /// Functie ce calculeaza a*b
  18. Mat prod(Mat A,Mat B)
  19. {
  20. Mat C;
  21. for(int i=0; i<3; ++i)
  22. {
  23. for(int j=0; j<3; ++j)
  24. {
  25. C.mat[i][j]=0;
  26. for(int k=0; k<3; ++k)
  27. C.mat[i][j]=(C.mat[i][j]%MOD +( 1LL*(A.mat[i][k]%MOD)*(B.mat[k][j]%MOD))%MOD)%MOD;
  28. }
  29. }
  30. return C;
  31. }
  32. Mat pwr(Mat mat,int n)
  33. {
  34. if(!n)
  35. return nullMat;
  36. if(n%2)
  37. return prod(mat,pwr(prod(mat,mat),n/2));
  38. return pwr(prod(mat,mat),n/2);
  39. }
  40.  
  41. int main()
  42. {
  43. int t;
  44. fin>>t;
  45. int n,a,b,u,v,w;
  46. while(t--)
  47. {
  48. fin>>n>>a>>b>>u>>v>>w;
  49. fMat.mat[0][0]=u;
  50. fMat.mat[1][0]=v;
  51. fMat.mat[2][0]=w;
  52. initMat.mat[0][0]=0; initMat.mat[0][1]=1; initMat.mat[0][2]=0;
  53. initMat.mat[1][0]=0; initMat.mat[1][1]=0; initMat.mat[1][2]=1;
  54. initMat.mat[2][0]=1; initMat.mat[2][1]=-b; initMat.mat[2][2]=-a;
  55. for(int i=0;i<3;++i)
  56. for(int j=0;j<3;++j)
  57. if(i!=j)
  58. nullMat.mat[i][j]=0;
  59. else
  60. nullMat.mat[i][j]=1;
  61. Put=pwr(initMat,n-2);
  62. Cmat=prod(Put,fMat);
  63. for(int i=2; i>=0; --i)
  64. {
  65. if(Cmat.mat[i][0]<0)
  66. Cmat.mat[i][0]+=MOD;
  67. fout<<Cmat.mat[i][0]<<' ';
  68. }
  69. fout<<'\n';
  70. }
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement