/* -*- coding: utf-8 -*- * * 982.cc: No.982 Add - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_A = 100; const int MAX_B = 100; const int MAX_N = MAX_A * MAX_A + MAX_B * MAX_B; /* typedef */ /* global variables */ bool used[MAX_N + 1]; /* subroutines */ template T gcd(T m, T n) { // m > 0, n > 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } /* main */ int main() { int a, b; scanf("%d%d", &a, &b); if (gcd(a, b) > 1) { puts("-1"); return 0; } int maxn = a * a + b * b; for (int x = 0; x <= a; x++) for (int y = 0, n; (n = a * x + b * y) <= maxn; y++) used[n] = true; int cnt = 0; for (int n = 0; n <= maxn; n++) if (! used[n]) cnt++; printf("%d\n", cnt); return 0; }