jrMz and angles
jrMz has two types of angles, one type of angle is an interior angle of nnn-sided regular polygon, and the other type of angle is an interior angle of mmm-sided regular polygon. jrMz wants to use them to make up an angle of 360 degrees, which means, jrMz needs to choose some or none of the angles which belong to the first type and some or none of the angles which belong to the second type so that the sum value of the angles chosen equals 360 degrees. But jrMz doesn’t know whether it is possible, can you help him?
The first line contains an integer T(1≤T≤10)Tleft(1leq Tleq10 ight)T(1≤T≤10)——The number of the test cases. For each test case, the only line contains two integersn,m(1≤n,m≤100)n,mleft(1leq n,mleq100 ight)n,m(1≤n,m≤100) with a white space separated.
For each test case, the only line contains a integer that is the answer.
3 4 8 3 10 5 8
Yes Yes NoHintIn test case 1, jrMz can choose 1 angle which belongs to the first type and 2 angles which belong to the second type, because 90+135+135=360. In test case 2, jrMz can choose 6 angles which belong to the first type, because6 imes60=360. In test case 3, jrMz can’t make up an angle of 360 degrees.
#include <cstdio> #include <cmath> #include <queue> #include <cstring> #include <stack> #include <map> #include <vector> #include <iostream> #include <algorithm> #define MAX_N 10006 #define MIN(a, b) (a > b)? a: b #define MAX(a, b) (a < b)? a: b using namespace std; int main() { int t,a, b; scanf("%d", &t); while (t--) { bool flag = true; scanf("%d %d", &a, &b); double da = (a - 2) * 180 / a; double db = (b - 2) * 180 / b; for (int i = 0; i <= 105; i++) { for (int j = 0; j <= 105; j++) { if (i * da + j * db == 360) { flag = false; break; } } } if (flag) printf("No "); else printf("Yes "); } return 0; }