Another One of the easiest problem like Hasmot the brave warrior:
we know that
a x b= gcd(a,b) x lcm(a,b)
or gcd(a,b) x lcm(a,b)= a x b ....................(1)
Input is :
gcd(a,b) and lcm(a,b)
output :
a=?
b=?
from equation (i)
there is symmetry
try:
from forward:
a=12
b=18
gcd(12,18)=6
lcm(12,18)=36
12 x 18 = 6 x 36
from reverse:
a=6
b=36
gcd(6,36)= 6
lcm(6,36)= 36
6 x 36 = 6 x 36
ha ha ha ............
just :
input = output if b is divisible by a
otherwise
print -1
11388 - GCD LCM
Moderator: Board moderators
-
- Learning poster
- Posts: 64
- Joined: Fri Sep 25, 2009 11:29 am
- Location: Chittagong,University of chittagong
- Contact:
Re: 11388 - GCD LCM
Try to catch fish rather than asking for some fishes.
Re: 11388 - GCD LCM
Nice problem lol....sometimes simple problems require deep thinking
![:wink:](./images/smilies/icon_wink.gif)
![:wink:](./images/smilies/icon_wink.gif)
![:wink:](./images/smilies/icon_wink.gif)
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
Re: 11388 - GCD LCM
Can anyone please explain me how can i know that a is minimized or not...
![:(](./images/smilies/icon_frown.gif)
""output the pair for which a is minimized. In case there is no such pair, output -1.""
what does this sentence means??![:(](./images/smilies/icon_frown.gif)
![:(](./images/smilies/icon_frown.gif)
![:(](./images/smilies/icon_frown.gif)
""output the pair for which a is minimized. In case there is no such pair, output -1.""
what does this sentence means??
![:(](./images/smilies/icon_frown.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11388 - GCD LCM
if L%G!=0
print -1
else
print a=G and b=L
print -1
else
print a=G and b=L
Check input and AC output for thousands of problems on uDebug!