Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("puteri5.in");
  8. ofstream fout("puteri5.out");
  9.  
  10. typedef int NrMare[3000];
  11.  
  12. NrMare aux;
  13. NrMare unu;
  14. NrMare t1, t2, t3, t4, t5, t6;
  15.  
  16. int* adunare(NrMare x, NrMare y);
  17.  
  18. int* inmultire(NrMare x, NrMare y)
  19. {
  20. NrMare z = {0};
  21.  
  22. z[0] = x[0] + y[0] - 1;
  23.  
  24. for(int i = 1; i <= x[0]; i++)
  25. for(int j = 1; j <= y[0]; j++)
  26. z[i + j - 1] += x[i] * y[j];
  27.  
  28. int t = 0;
  29.  
  30. for(int i = 1; i <= z[0]; i++)
  31. {
  32. t += z[i];
  33. z[i] = t % 10;
  34. t /= 10;
  35. }
  36.  
  37. while(t)
  38. {
  39. z[++z[0]] = t % 10;
  40. t /= 10;
  41. }
  42.  
  43. return z;
  44. }
  45.  
  46. int* ep(NrMare n, int putere)
  47. {
  48. if(putere == 0)
  49. return unu;
  50. else if(putere == 1)
  51. return n;
  52. else if(putere % 2 == 0)
  53. return ep(inmultire(n, n), putere >> 1);
  54. else
  55. return inmultire(n, ep(inmultire(n, n), putere >> 1));
  56. }
  57.  
  58. int ep(int n, int putere)
  59. {
  60. if(putere == 0)
  61. return 1;
  62. else if(putere == 1)
  63. return n;
  64. else if(putere % 2 == 0)
  65. return ep(n * n, putere >> 1);
  66. else
  67. return n * ep(n * n, putere >> 1);
  68. }
  69.  
  70. void afisare(NrMare x)
  71. {
  72. for(int i = 1; i <= x[0]; i++)
  73. fout << x[i];
  74.  
  75. fout << '\n';
  76. }
  77.  
  78. int* adunare(NrMare x, NrMare y)
  79. {
  80. for(int i = 1; i <= x[0]; i++)
  81. x[i] += y[i];
  82.  
  83. int t = 0;
  84.  
  85. for(int i = 1; i <= x[0]; i++)
  86. {
  87. t += x[i];
  88. x[i] = t % 10;
  89. t /= 10;
  90. }
  91.  
  92. while(t)
  93. {
  94. x[++x[0]] = t % 10;
  95. t /= 10;
  96. }
  97. }
  98.  
  99.  
  100. int main()
  101. {
  102. unu[1] = unu[0] = 1;
  103. int a, b, c;
  104.  
  105. fin >> a >> b >> c;
  106.  
  107. t1[0] = t2[0] = t3[0] = t4[0] = t5[0] = t6[0] = 1;
  108. t1[1] = t2[1] = a;
  109. t3[1] = t4[1] = b;
  110. t5[1] = t6[1] = c;
  111.  
  112. afisare(ep(t2, ep(c, b)));
  113.  
  114. memcpy(t1, ep(t1, ep(b, c)), sizeof(ep(t1, ep(b, c))));
  115. memcpy(t2, ep(t2, ep(c, b)), sizeof(ep(t2, ep(c, b))));
  116. memcpy(t3, ep(t3, ep(a, c)), sizeof(ep(t3, ep(a, c))));
  117. memcpy(t4, ep(t4, ep(c, a)), sizeof(ep(t4, ep(c, a))));
  118. memcpy(t5, ep(t5, ep(a, b)), sizeof(ep(t5, ep(a, b))));
  119. memcpy(t6, ep(t6, ep(b, a)), sizeof(ep(t6, ep(b, a))));
  120.  
  121.  
  122. afisare(t1);
  123. afisare(t2);
  124. afisare(t3);
  125. afisare(t4);
  126. afisare(t5);
  127. afisare(t6);
  128.  
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement