php alice consecutive stones

I have to find a php code to solve a math problem.

A and B are playing a game of stones. A start always the game.
They will pick in turns 2 consecutive stones from a line until there are no consecutive stones –> condition1: stone i and stone i+1, where 1 ≤ i ≤ N−1

The line has N stones and are indexed from 1 to N. Condition2: N (1 ≤ N ≤ 10 000 000)

If the number of stone left is odd, A wins. Otherwise, B wins.

This is my code. It does not work.

    <?php

while (fscanf(STDIN, '%d', $NStones) === 2) {
    $res = ($NStones % 2 == 1 ? "Alice" : "Bob");
    fprintf(STDOUT, "%d\n", $res);
}

?>

I want to understand how to turn a mathematical thought into php code. My math solution is that NStones/(A+B)*random(i,i+1) = remainder, which if it is not %2 returns A. Otherwise, returns B.

php alice consecutive stones