[ACM]Q10299: Relatives

[ACM]Q10299: Relatives


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace Q10299
{
    class Program
    {
        static private BigInteger _n; static private bool ntof; static private BigInteger sum;
        static void Main(string[] args)
        {
            for (; ; )
            {
            labeln: Console.Write("n>>>");
                ntof = BigInteger.TryParse(Console.ReadLine(), out _n);
                if (!ntof) goto labeln;
                BigInteger count = 0;
                for (BigInteger i = 1; i < _n; i++)
                    count += coPrime(_n, i) ? 1 : 0;
                Console.WriteLine("Ans={0}", count);
            }
        }
        static public bool coPrime(BigInteger x, BigInteger y)
        {
            while (true)
            {
                if (x == 1 || y == 1) return true;
                if (x > y) { x %= y; if (x == 0)return false; }
                else if (x < y) { y %= x; if (y == 0) return false; }
                else if (x == y) return false;
            }
        }
    }
}