generated from OPCODE-Open-Spring-Fest/template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from Ayushivam22/day10
feat: easy day 10 solution
- Loading branch information
Showing
3 changed files
with
27 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
// Write Your Code here | ||
#include <bits/stdc++.h> | ||
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 a, b, m; | ||
cin >> a >> b >> m; | ||
|
||
cout << BinExpo(a, b, m) << endl; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1 @@ | ||
#include <bits/stdc++.h> | ||
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; | ||
} | ||
} | ||
// Write your code here |