2016年11月27日 星期日

Q10193: All You Need Is Love

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1134

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
int n=Integer.parseInt(scn.nextLine()),i=0;
for(i=1;i<=n;i++){
String s1=scn.nextLine(),s2=scn.nextLine();
int a=Integer.parseInt(s1,2),b=Integer.parseInt(s2,2);
while((a%=b)!=0&&(b%=a)!=0);
if((a+b)!=1)
System.out.printf("Pair #%d: All you need is love!\n",i);
else
System.out.printf("Pair #%d: Love is not all you need!\n",i);
}
}
/*題目:Q10193: All You Need Is Love
作者:1010
時間:西元 2016 年 11 月 */
}
這題利用GCD去判斷當小於1 Pair #%d: Love is not all you need! 反之
GCD=>最大公因數