Challenge: Superpowers of 2
Subdomeniu: Number Theory (number-theory)
Scor cont: 60.0 / 60
Submission status: Accepted
Submission score: 1.0
Submission ID: 464733548
Limbaj: cpp14
Link challenge: https://www.hackerrank.com/challenges/superpowers/problem
Cerinta
You will be given two integers $a, b$. You are required to output the result of $2^{(2^a)}$ mod $b$.
**Constraints**
$1 \le a, b \le 10^6$
Input Format
First and only line of the input will contain two integers $a, b$ separated by a single blank space.
Output Format
Output the desired result in a single line.
Cod sursa
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
int a, b, ans = 2;
cin >> a >> b;
for(int i = 1; i <= a; i++){
ans = (1LL * ans * ans) % b;
}
cout << ans % b << endl;
return 0;
}
HackerRank Number Theory – Superpowers of 2
