Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- ifstream fin("puteri5.in");
- ofstream fout("puteri5.out");
- typedef int NrMare[3000];
- NrMare aux;
- NrMare unu;
- NrMare t1, t2, t3, t4, t5, t6;
- int* adunare(NrMare x, NrMare y);
- int* inmultire(NrMare x, NrMare y)
- {
- NrMare z = {0};
- z[0] = x[0] + y[0] - 1;
- for(int i = 1; i <= x[0]; i++)
- for(int j = 1; j <= y[0]; j++)
- z[i + j - 1] += x[i] * y[j];
- int t = 0;
- for(int i = 1; i <= z[0]; i++)
- {
- t += z[i];
- z[i] = t % 10;
- t /= 10;
- }
- while(t)
- {
- z[++z[0]] = t % 10;
- t /= 10;
- }
- return z;
- }
- int* ep(NrMare n, int putere)
- {
- if(putere == 0)
- return unu;
- else if(putere == 1)
- return n;
- else if(putere % 2 == 0)
- return ep(inmultire(n, n), putere >> 1);
- else
- return inmultire(n, ep(inmultire(n, n), putere >> 1));
- }
- int ep(int n, int putere)
- {
- if(putere == 0)
- return 1;
- else if(putere == 1)
- return n;
- else if(putere % 2 == 0)
- return ep(n * n, putere >> 1);
- else
- return n * ep(n * n, putere >> 1);
- }
- void afisare(NrMare x)
- {
- for(int i = 1; i <= x[0]; i++)
- fout << x[i];
- fout << '\n';
- }
- int* adunare(NrMare x, NrMare y)
- {
- for(int i = 1; i <= x[0]; i++)
- x[i] += y[i];
- int t = 0;
- for(int i = 1; i <= x[0]; i++)
- {
- t += x[i];
- x[i] = t % 10;
- t /= 10;
- }
- while(t)
- {
- x[++x[0]] = t % 10;
- t /= 10;
- }
- }
- int main()
- {
- unu[1] = unu[0] = 1;
- int a, b, c;
- fin >> a >> b >> c;
- t1[0] = t2[0] = t3[0] = t4[0] = t5[0] = t6[0] = 1;
- t1[1] = t2[1] = a;
- t3[1] = t4[1] = b;
- t5[1] = t6[1] = c;
- afisare(ep(t2, ep(c, b)));
- memcpy(t1, ep(t1, ep(b, c)), sizeof(ep(t1, ep(b, c))));
- memcpy(t2, ep(t2, ep(c, b)), sizeof(ep(t2, ep(c, b))));
- memcpy(t3, ep(t3, ep(a, c)), sizeof(ep(t3, ep(a, c))));
- memcpy(t4, ep(t4, ep(c, a)), sizeof(ep(t4, ep(c, a))));
- memcpy(t5, ep(t5, ep(a, b)), sizeof(ep(t5, ep(a, b))));
- memcpy(t6, ep(t6, ep(b, a)), sizeof(ep(t6, ep(b, a))));
- afisare(t1);
- afisare(t2);
- afisare(t3);
- afisare(t4);
- afisare(t5);
- afisare(t6);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement