We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
import math
import os
import random
import re
import sys
#
Complete the 'solve' function below.
#
The function is expected to return an INTEGER.
The function accepts following parameters:
1. INTEGER n
2. INTEGER m
#
from math import gcd
def solve(A):
if A[0] == 1 or A[1] == 1:
return 1
m = min(A)
M = m + 1
###CALCULATION OF PRIMES<=M.###
Primes = [0]*M
i = 2
while i*i<M:
if not Primes[i]:
j = i
k = i*j
while k<M:
Primes[k] = 1
j+=1
k = i*j
i+=1
primes = []
for i in range(2,M):
if Primes[i]==0:
primes.append(i)
################################
res = 1
MOD = 10**9+7
f,s = A
for p in primes:
temp = p
while temp<=m:
res = (res*pow(p,(f//temp) * (s//temp),MOD))%MOD
temp*=p
return res%MOD
A = list(map(int, input().split()))
print(solve(A))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
GCD Product
You are viewing a single comment's thread. Return to all comments →
!/bin/python3
import math import os import random import re import sys
#
Complete the 'solve' function below.
#
The function is expected to return an INTEGER.
The function accepts following parameters:
1. INTEGER n
2. INTEGER m
#
from math import gcd
def solve(A): if A[0] == 1 or A[1] == 1: return 1 m = min(A) M = m + 1
A = list(map(int, input().split())) print(solve(A))