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.
def find_closest_multiple(a, b, x):
ab = pow(a, b)
lower_multiple = (ab // x) * x
upper_multiple = lower_multiple + x
if ab - lower_multiple <= upper_multiple - ab:
return int(lower_multiple)
else:
return int(upper_multiple)
def main():
import sys
input = sys.stdin.read
data = input().split()
T = int(data[0])
index = 1
results = []
for _ in range(T):
a = int(data[index])
b = int(data[index+1])
x = int(data[index+2])
index += 3
result = find_closest_multiple(a, b, x)
results.append(result)
for result in results:
print(result)
if name == "main":
main()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Closest Numbers
You are viewing a single comment's thread. Return to all comments →
import math
def find_closest_multiple(a, b, x): ab = pow(a, b) lower_multiple = (ab // x) * x upper_multiple = lower_multiple + x
def main(): import sys input = sys.stdin.read data = input().split()
if name == "main": main()