UVA10193




Sample Input

5
11011
11000
11011
11001
111111
100
1000000000
110
1010
100

Sample Output

Pair #1: All you need is love!
Pair #2: Love is not all you need!
Pair #3: Love is not all you need!
Pair #4: All you need is love!
Pair #5: All you need is love!


解法: 先轉成十進制後 使用輾轉相除法


import java.util.Scanner;

public class UVA10193 {

 public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

  int count = Integer.parseInt(sc.nextLine());

  int pair = 1;

  for (int i = 0; i < count; i++) {

   int S1 = Integer.parseInt(sc.nextLine(), 2);
   int S2 = Integer.parseInt(sc.nextLine(), 2);

   int temp = 0;
   // Euclidean algorithm
   while (S1 % S2 != 0) {

    temp = S1 % S2;
    S1 = S2;
    S2 = temp;

   }

   System.out.println(S2 != 1 ? "Pair #" + pair
     + ": All you need is love!" : "Pair #" + pair
     + ": Love is not all you need!");

   pair++;
  }

  sc.close();
 }

}