Challenge: Restaurant
Subdomeniu: Fundamentals (fundamentals)
Scor cont: 30.0 / 30
Submission status: Accepted
Submission score: 1.0
Submission ID: 464726717
Limbaj: python3
Link challenge: https://www.hackerrank.com/challenges/restaurant/problem
Cerinta
Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size $l \times b$ into smaller identical pieces such that each piece is a square having maximum possible side length with no left over piece of bread.
Input Format
The first line contains an integer $T$. $T$ lines follow. Each line contains two space separated integers $l$ and $b$ which denote length and breadth of the bread.
Output Format
$T$ lines, each containing an integer that denotes the number of squares of maximum size, when the bread is cut as per the given condition.
Constraints
+ $1 \le T \le 1000$
+ $1 \le l, b \le 1000$
Cod sursa
#!/bin/python3
import math
import os
import random
import re
import sys
def restaurant(l, b):
if(l==b):
return 1
else:
index = min(l,b)
for i in range(1,index+1):
if(l%i==0 and b%i==0):
val1 = l//i
val2 = b//i
final = val1 * val2
return final
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
first_multiple_input = input().rstrip().split()
l = int(first_multiple_input[0])
b = int(first_multiple_input[1])
result = restaurant(l, b)
fptr.write(str(result) + '\n')
fptr.close()
HackerRank Fundamentals – Restaurant
