From c5fcf7179a83ef65c86c6a4a390029149e518649 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Tue, 5 Oct 2021 21:49:54 +0200 Subject: Duzy commit ze smieciami --- semestr-4/aisd/themis/AISDPOTEGOWANIE.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 semestr-4/aisd/themis/AISDPOTEGOWANIE.cpp (limited to 'semestr-4/aisd/themis/AISDPOTEGOWANIE.cpp') 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 +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 -- cgit v1.2.3