// Run time: 0.000
#include <stdio.h>
#include <string.h>
#define N 30
int calculate(int *arr, int len);
int gcd(int a, int b);
int main()
{
char s1[N+1];
char s2[N+1];
int arr1[N];
int arr2[N];
int i; // (for loop)'s count
int n; // 輸入組數
int cnt = 0; // for output counting
int len1, len2; // input string's length
int a, b; // trans to binary
scanf("%d\n", &n);
while (n--)
{
gets(s1);
gets(s2);
len1 = strlen(s1);
len2 = strlen(s2);
for ( i = 0; i < len1; i++)
arr1[i] = s1[i] - '0';
for ( i = 0; i < len2; i++)
arr2[i] = s2[i] - '0';
a = calculate(arr1, len1);
b = calculate(arr2, len2);
if (gcd(a, b) != 1)
printf("Pair #%d: All you need is love!\n", ++cnt);
else
printf("Pair #%d: Love is not all you need!\n", ++cnt);
}
return 0;
}
int calculate(int *arr, int len)
{
int i;
int sum = 0;
int weight = 1;
for ( i = len-1; i >= 0; i--)
{
sum += arr[i]*weight;
weight *= 2;
}
return sum;
}
int gcd(int a, int b)
{
if (!a)
return b;
else
return gcd(b%a, a);
}
2009年2月25日 星期三
Q10193: All You Need Is Love
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言