HCF/GCD of 2 numbers - python,Java - Spicy Coders

Recent

Tuesday, July 18, 2017

HCF/GCD of 2 numbers - python,Java


The program must accept two numbers X and Y and then print their HCF/GCD. Input Format: The first line denotes the value of X. The second line denotes the value of Y. Output Format: The first line contains the HCF of X and Y. 

Boundary Conditions:

1 <= X <= 999999 1 <= Y <= 999999 

Example Input/Output 1:

Input: 30 40 

Output: 10 

Example Input/Output 2: 

Input: 15 10

Output: 5

Example Input/Output 2:
Input:
999999999999 151515151515

Output:
30303030303

Source Code: //Python

import math
s,e=int(input()),int(input())
print(math.gcd(s,e))

Source Code: //Java

import java.util.*;
import java.math.*;
public class Hello {
    public static void main(String[] args) {
                        Scanner sc=new Scanner(System.in);
                        BigInteger s1=sc.nextBigInteger();
                        BigInteger s2=sc.nextBigInteger();
                        System.out.println(s1.gcd(s2));
            }

}

No comments:

Post a Comment