Pages

Wednesday 19 September 2012

UVA - 10193 - All You Need Is Love

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        StringBuffer sb = new StringBuffer("");
        String s1="",s2="";
        int n=Integer.parseInt(br.readLine());
        for(int i=1;i<n+1;i++){
            s1=br.readLine();
            int x=Integer.parseInt(s1, 2);
            s2=br.readLine();
            int y=Integer.parseInt(s2, 2);
            if(s1.charAt(0)!='0' && s2.charAt(0)!='0' && s1.length()!=1 && s2.length()!=1){
                int g=gcd(x,y);
                if(g==1)
                    sb.append("Pair #").append(i).append(": Love is not all you need!\n");
                else
                    sb.append("Pair #").append(i).append(": All you need is love!\n");
            }
             else
                    sb.append("Pair #").append(i).append(": Love is not all you need!\n");
        }
        System.out.print(sb);
    }
   
     public static int gcd(int x, int y) {
         if (y==0)
            return x;
         return gcd(y, x % y);
     }
}

No comments:

Post a Comment