You are on page 1of 4

Problem Statement

monika4
Alice and Bob
aniy

are playing a game on two


monikachiraniyaC
numbers, A, and B.
31-JUL-20
monike
Bob has to select a
gcd(A, B). 91@gmail.c
random number X from [1, B]. Bob wins the game if gcd(X, B)
091@gmg
=

mpnikach
Findthe probability of Bob winning the qame, for given A and
integerpart of the probability after multiplying it by 10.
monikachirat
B. Let S denote the
31-JUL

Yourtask is to find S.
@gmail.com
91@gme
a091@gmg
Input Format
The first line contains a long, A, denoting the first given number.
22
menikachir
UL
2022

The next line contains long, B, denoting


a the second given number.

monikad
Constraints
1= A = 10 12
1c B 10 12
Code is
monikachiraniya091@
1
31-JUL-202
Sample Input SampleOutput
1000000
Explanation a

gcd(4, 1)=1. Bob will1


9co
0

choose a random number


9 1

from [1], hence his


probability of winning is

1 Thus, output

monikachiraniya091
2
2
500000
1 1000000=1000000

gcd(2, 2)= 2. Bob will


choose a random number
from 1,2], hence his
probability of winning is
@gme

O.5(will win for 2). Thus


Outpu
0.5 1000000-500000.

400000 gcd(2, 10) 2. Bob will g m g


2
choose a random number
10

monikachiraniy
31
09 from
[1,2,3.4,5,6,7,8,9,10], 2
hence his probability of
winning is 0.4(will win for
2,4,6,8). Thus, output
mo
0.4 1000000-400000
import java.io.";
2 import java.util.a
3 import java,lang.Math;

5
6 class Solution
7 publicstatic int BobProbab(long A,long B)
I Write your code here
9
10
11
12 public static void main(Stringl args)
13 Scanner scan= new Scanner(System.in)
14
15 long A Long.parsel.ong(scan.nextLine0.trim0)
=

16
17 long B Long-parsel.ong(scan.nextLine0.trim)
18
19 int result= BobProbab(A, B);
20
21 System.out.printin(result);
22
23
1import sys

I
4 def BobProbab(A, B):
5 # Write your code here

1
8
9 def main0:
10 A= sys.stdin.readline0.strip0
11
12 B sys.stdin.readline0.strip0
13
14 result BobProbab(A, B)
15
16 print(result)
17
18
1 9 if n a m e
="main_"
20 main0

You might also like