ull spinningRings(ull innerMax, ull outerMax){ ull n = innerMax + 1, m = outerMax + 1; if (m < n) { ull r = n % m; if (m % 2 == r % 2) return n - m + (m - r) / 2; if (r % 2 == 0) return n - r / 2; return2 * n - (m + (2 * r + 1) % m - 1) / 2; } if (n % 2 == 0) return n / 2; ull r = m % n; if (r == 0) return m; if (r % 2 == 1) return m + (n - r) / 2; return m + n - r / 2; }