From b53c9a525768e5fdd4f05c0152d97bacdaf4790f Mon Sep 17 00:00:00 2001 From: AKS Date: Sun, 7 Apr 2024 12:43:48 +0530 Subject: [PATCH] feat: day8 easy solution --- Easy/Day8/Solution.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Easy/Day8/Solution.cpp b/Easy/Day8/Solution.cpp index 7056c69..9020e8d 100644 --- a/Easy/Day8/Solution.cpp +++ b/Easy/Day8/Solution.cpp @@ -1 +1,30 @@ -// Write your code here \ No newline at end of file +#include +using namespace std; +long long BinExpo(long long a, long long b, long long m) +{ + // basse case + if (b == 0) + return 1; + // recursive case + long long res = BinExpo(a, b / 2, m); + if (b & 1) // if b is odd + { + return ((a * (res % m)) % m * (res % m)) % m; + } + else + { + return (res * res) % m; + } +} +int main() +{ + long long m = 1e9 + 7; + int t; + cin >> t; + while (t--) + { + long long a, b; + cin >> a >> b; + cout << BinExpo(a, b, m) << endl; + } +} \ No newline at end of file