Code ne

mail@pastecode.io avatar
unknown
gcode
3 years ago
824 B
604
Indexable
Never
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in); 
	int a = sc.nextInt();  
	int b = sc.nextInt();   
	if(b == 0) { 
		System.out.println("INVALID"); 		System.exit(0);
	}
		
	int tu = a / UCLN(a, b);  
	int mau = b / UCLN(a, b); 
	int res = tu / mau; 
	 
	if( res * mau == tu) { 
		System.out.println(res);  
		System.exit(0);
	}


	if(b < 0 && a < 0){ 
		System.out.println(tu + " " + mau); System.exit(0);
	}
	if(b < 0 ) { 
		System.out.println(setUnsigned(tu) + " " + setUnsigned(mau)); 
	}else{  
	}
		System.out.println(tu + " " + mau); 
	}

	static int UCLN(int a, int b) { 
		if (b == 0) return a; 
		return UCLN(b, a%b);
	}  
	public static int  setUnsigned(int n) { 
			n *= -1;
		return n;
	}
}