GCD of a number raised to some power and another number | CPP program to find GCD of a ^ n and b . ; Returns GCD of a ^ n and b . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; typedef long long int ll ; ll gcd ( ll a , ll b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } ll powGCD ( ll a , ll n , ll b ) { for ( int i = 0 ; i < n ; i ++ ) a = a * a ; return gcd ( a , b ) ; } int main ( ) { ll a = 10 , b = 5 , n = 2 ; cout << powGCD ( a , n , b ) ; return 0 ; }