View Code of Problem 59

import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
	     Scanner scan=new Scanner(System.in);
	   
	     
	     int s1 =scan.nextInt();
         int s2 =scan.nextInt();       
	     
	     for(int b=s1;b>0;b--){
	    	 if(s1%b==0&&s2%b==0){
	    		 System.out.println(b); 
	    		 break;
	    	 }
	     }
	     
	     for(int b=s1;;b++){
	    	 if(b%s1==0&&b%s2==0){
	    		 System.out.println(b); 
	    		 break;
	    	 }
	     }
	
	     }
 
	}

Double click to view unformatted code.


Back to problem 59