Dcoder icon

Simple multiple problem @ Dcoder

By Lochard | As a newbie programmer | 3 Aug 2023


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

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.