You are viewing a single comment's thread. Return to all comments →
Can anyone please tell me how to improve my code efficiency? I wrote this but its showing runtime error for most testcases. It is in python 3.
from fractions import gcd n = int(input()) A = 1 B = 1 for _ in range(n): p1,b1,a1 = map(int, input().split()) A *= pow(p1,a1) B *= pow(p1,b1) num = 0 for j in range(B,A+1,B): for k in range(B,A+1,B): if j <= k and gcd(j,k) == B and j*k == A*B: num += j+k print(num%(pow(10,9)+7))
Seems like cookies are disabled on this browser, please enable them to open this website
Manasa and Calculations
You are viewing a single comment's thread. Return to all comments →
Can anyone please tell me how to improve my code efficiency? I wrote this but its showing runtime error for most testcases. It is in python 3.