This is the performance version of [this kata](https://www.codewars.com/kata/59afff65f1c8274f270020f5).
---
Imagine two rings with numbers on them. The inner ring spins clockwise and the outer ring spins anti-clockwise. We start with both rings aligned on 0 at the top, and on each move we spin each ring by 1. How many moves will it take before both rings show the same number at the top again?
The inner ring has integers from 0 to innerMax and the outer ring has integers from 0 to outerMax, where innerMax and outerMax are integers >= 1.
```
e.g. if innerMax is 2 and outerMax is 3 then after
1 move: inner = 2, outer = 1
2 moves: inner = 1, outer = 2
3 moves: inner = 0, outer = 3
4 moves: inner = 2, outer = 0
5 moves: inner = 1, outer = 1
Therefore it takes 5 moves for the two rings to reach the same number
Therefore spinningRings(2, 3) = 5
```
```
e.g. if innerMax is 3 and outerMax is 2 then after
1 move: inner = 3, outer = 1
2 moves: inner = 2, outer = 2
Therefore it takes 2 moves for the two rings to reach the same number
spinningRings(3, 2) = 2
```
---
Test input range:
- `100` tests with `1 <= innerMax, outerMax <= 10000`
- `400` tests with `1 <= innerMax, outerMax <= 2^48`
def spinning_rings(inner_max, outer_max):
    p = inner_max + 1
    q = outer_max + 1
    move = 1
    while (-move) % p != move % q:
        if (-move) % p >= q:
            move = move // p * p + p - q + 1
        elif move % q >= p:
            move = move // q * q + q
        elif (-move) % p > move % q and ((-move) % p + move % q) % 2 == 0:
            move += ((-move) % p - move % q) // 2
        else:
            move = min((move - 1) // p * p + p, (move - 1) // q * q + q) + 1
    return move
def spinning_rings(inner_max, outer_max):
    p = inner_max + 1
    q = outer_max + 1
    move = 1
    while (-move) % p != move % q:
        if (-move) % p >= q:
            move = move // p * p + p - q + 1
        elif move % q >= p:
            move = move // q * q + q
        elif (-move) % p > move % q and ((-move) % p + move % q) % 2 == 0:
            move += ((-move) % p - move % q) // 2
        else:
            move = min((move - 1) // p * p + p, (move - 1) // q * q + q) + 1
    return move