#include using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll calc(ll x, ll y) { if (x > y) swap(x, y); ll ans = 1; for (ll i = 1; i * i <= y; i++) if (y % i == 0) { if (y == i * (1 + x / gcd(x, i))) ans += calc(x, i); if (i * i != y) { ll j = y / i; if (y == j * (1 + x / gcd(x, j))) ans += calc(x, j); } } //printf("calc(%lld, %lld) = %lld\n", x, y, ans); return ans; } int main() { int T, x, y; scanf("%d", &T); for (int t = 1; t <= T; t++) scanf("%d%d", &x, &y), printf("Case #%d: %lld\n", t, calc(x, y)); return 0; }