package com.codegym.task.task14.task1420;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
int b = Integer.parseInt(br.readLine());
if (a < 0 || b < 0 ) {
throw new NumberFormatException();
}
System.out.println(gcd(a, b));
}
public static int gcd(int a, int b){
int R;
while((a % b) > 0){
R = a % b;
a = b;
b = R;
}
return b;
}
}
package com.codegym.task.task14.task1420;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
/*
GCD
Pseudo Code of the Algorithm-
Step 1: Let a, b be the two numbers
Step 2: a mod b = R
Step 3: Let a = b and b = R
Step 4: Repeat Steps 2 and 3 until a mod b is greater than 0
Step 5: GCD = b
Step 6: Finish
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
int b = Integer.parseInt(br.readLine());
if (a < 0 || b < 0 ) {
throw new NumberFormatException();
}
System.out.println(gcd(a, b));
}
public static int gcd(int a, int b){
int R;
while((a % b) > 0){
R = a % b;
a = b;
b = R;
}
return b;
}
}