As a newbie programmer

Simple multiple problem @ Dcoder

Dcoder icon

Problem: You are given 2 numbers N and M. You have to find the smallest number which when multiplied to N makes it a multiple of M.

 

Input: First line contains T, number of test cases.

Each of the next T lines contains two numbers, N and M.

Output: For each test case, print the required answer.

Constraints: 1 <= T <= 100

1 <= N, M <= 10^6

Sample Input: 2

4 7

18 6

 

Sample Output: 

7

1

from math import gcd

for t in range( int( input() ) ):
    n, m = map( int, input().split() )
    print( m // gcd( n, m ) )

How do you rate this article?

2


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?