-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10193 - all you need is love
47 lines (44 loc) · 1.02 KB
/
10193 - all you need is love
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
計算給定兩數是否互質;
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#define INF 0x7fffffff
using namespace std;
char str1[31], str2[31];
int gcd(int a, int b) {
if(b == 0) return a;
return gcd(b, a % b);
}
int parse(char *str) {
int len = strlen(str);
int sum = 0;
for(int i = 0; i < len; i ++) {
sum += (str[i] - '0') * pow(2, len - i - 1);
}
return sum;
}
int main()
{
int cases;
scanf("%d", &cases);
for(int i = 1; i <= cases; i ++) {
printf("Pair #%d: ", i);
int dec1, dec2;
scanf("%s%s", str1, str2);
dec1 = parse(str1);
dec2 = parse(str2);
if(dec1 < dec2) swap(dec1, dec2);
if(gcd(dec1, dec2) != 1)
printf("All you need is love!\n");
else
printf("Love is not all you need!\n");
}
return 0;
}