A. Libra … Basic if…else structure

1 2 3 4 5 6 7 8 |
a,b,c,d = list(map(int, input().split())) if a+b > c+d: print('Left') elif a+b == c+d: print('Balanced') else: print('Right') |

B. Some Sums … I used brute force as the expected N is up to 10^4. So I just iterate all the numbers from 1 to N.

1 2 3 4 5 6 7 8 |
a,b,c,d = list(map(int, input().split())) if a+b > c+d: print('Left') elif a+b == c+d: print('Balanced') else: print('Right') |

C. Multiple Gift … I used kind of brute force here as well. Multiply current number by 2, 3, 4… and check if modulus is 0 each time.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
x, y = list(map(int, input().split())) count = 1 curr_num, next_num = x, x*2 multiplier = 2 while next_num <= y: if next_num%curr_num == 0: count += 1 multiplier = 2 curr_num = next_num else: multiplier += 1 next_num = curr_num * multiplier print(count) |