aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/aisd/themis/AISDPOTEGOWANIE.cpp
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-03-17 15:44:51 +0100
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-03-17 15:44:51 +0100
commita52f462140e3a38fb0f08d5ea74bdafe039bb428 (patch)
tree012f7c61b849579e175f43ce02578b5b654d1c11 /Semestr 4/aisd/themis/AISDPOTEGOWANIE.cpp
parent7eb19447e02fb0ec039253e25423926815f254a1 (diff)
Zmiana struktury folderu pstwo, dodane jakies listy
Diffstat (limited to 'Semestr 4/aisd/themis/AISDPOTEGOWANIE.cpp')
-rw-r--r--Semestr 4/aisd/themis/AISDPOTEGOWANIE.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/Semestr 4/aisd/themis/AISDPOTEGOWANIE.cpp b/Semestr 4/aisd/themis/AISDPOTEGOWANIE.cpp
new file mode 100644
index 0000000..c1b76fe
--- /dev/null
+++ b/Semestr 4/aisd/themis/AISDPOTEGOWANIE.cpp
@@ -0,0 +1,29 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+int fast_pow(int a, int b, int m)
+{
+ if (b == 0)
+ {
+ return 1;
+ }
+ long long p = fast_pow(a, b / 2, m);
+ p = (p * p) % m;
+ if (b % 2 == 0)
+ return (int)p;
+ return (p * (long long)a) % m;
+}
+
+int main()
+{
+ ios_base::sync_with_stdio(false);
+ cin.tie();
+ int t;
+ cin >> t;
+ while (t--)
+ {
+ int a, b, m;
+ cin >> a >> b >> m;
+ cout << fast_pow(a, b, m) << "\n";
+ }
+} \ No newline at end of file