import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  when (n /= 0) $ do
    mapM_ print $ solve n
    main

solve :: Int -> [Int]
solve n = (g . f) n
  where
    f x = nub [i ^ 2 `mod` x| i <- [1..x-1]]
    g xs = (map length . group . sort) [mn n (abs (xs !! i - xs !! j)) | i <- [0..l - 1], j <- [0..l - 1], i /= j]
      where
        l = length xs
        mn m x = min x (m - x)

toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine