out_of_theblue10

New scheme code

Oct 2nd, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #define MOD 1000000007
  4. using namespace std;
  5. int a[80][10][10], sol[10][10], mat[10][10], t, i, l, c, j;
  6. long long n, p;
  7. int main()
  8. {
  9. cin >> t;
  10. a[0][1][1] = a[0][3][3] = 3;
  11. a[0][1][2] = a[0][4][1] = 1;
  12. a[0][3][1] = -1;
  13. for(i = 0; (1LL<<i) <= 1000000000LL; i++)
  14. {
  15. for(l = 1; l <= 4; l++)
  16. for(c = 1; c <= 4; c++)
  17. for(j = 1; j <= 4; j++)
  18. {
  19. a[i+1][l][c] += ((long long)a[i][l][j]*a[i][j][c])%MOD;
  20. if(a[i+1][l][c] > MOD) a[i+1][l][c] -= MOD;
  21. }
  22. }
  23. while(t--)
  24. {
  25. cin >> n;
  26. p = n;
  27. memset(sol, 0, sizeof(sol));
  28. sol[1][1] = sol[2][2] = sol[3][3] = sol[4][4] = 1;
  29. for(i = 0; (1LL<<i) <= p; i++)
  30. if((1LL<<i)&p)
  31. {
  32. memset(mat, 0, sizeof(mat));
  33. for(l = 1; l <= 4; l++)
  34. for(c = 1; c <= 4; c++)
  35. for(j = 1; j <= 4; j++)
  36. {
  37. mat[l][c] += ((long long)sol[l][j]*a[i][j][c])%MOD;
  38. if(mat[l][c] > MOD) mat[l][c] -= MOD;
  39. }
  40. memcpy(sol, mat, sizeof(mat));
  41. }
  42. cout << 4*sol[1][2] << "\n"; //MODULO!
  43.  
  44. }
  45. return 0;
  46. }
  47. //
  48. //4*3*3*3*2
  49. //4*3*3*3*3*3=
  50. //
  51. //D[i] = prod[i-1] * 3 - D[i-1]
  52. //
  53. //(D[i], D[i-1], prod[i], prod[i-1]) *
  54. //
  55. // 3 1 0 0
  56. // 0 0 0 0
  57. //-1 0 3 0
  58. // 0 0 0 1
  59. //
  60. //
  61. //= (D[i+1] D[i] prod[i+1] prod[i])
Advertisement
Add Comment
Please, Sign In to add comment