Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class coprimes {
- public static void main(String[] args) throws IOException {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
- String linea;
- String num;
- int num1, num2;
- int t = 1;
- while ((linea = in.readLine()) != null) {
- int n = Integer.parseInt(linea);
- for (int i = 0; i < n; i++) {
- num = in.readLine();
- boolean xd = false;
- for (int j = 1; j < num.length() - 1; j++) {
- num1 = Integer.parseInt(num.substring(0, j));
- num2 = Integer.parseInt(num.substring(j, num.length()));
- if (gcd(num2, num1) == 1) {
- out.write("Ticket #" + t + ":\n");
- out.write(num1 + " " + num2 + "\n");
- t++;
- xd = true;
- break;
- }
- }
- if (xd == false) {
- out.write("Ticket #" + t + ":\nNot relative\n");
- t++;
- }
- }
- }
- in.close();
- out.flush();
- out.close();
- }
- public static int gcd(int a, int b) {
- if (a == 0)
- return b;
- while (b != 0) {
- if (a > b)
- a = a - b;
- else
- b = b - a;
- }
- return a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement