Example #1
0
    public static void UnevenNumbers()
    {
        var N     = IOLibrary.ReadInt();
        var count = Enumerable.Range(1, N)
                    .Select(num => MathLibrary.Digits(num))
                    .Count(num => num % 2 == 1);

        Console.WriteLine(count);
    }
Example #2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="n"></param>
    /// <returns></returns>
    public static int[] GetSubsetFromBits(int n)
    {
        var digits = MathLibrary.Digits(n, 2);
        var array  = new int[digits];

        for (var i = 0; i < digits; i++)
        {
            if (MathLibrary.TestBit(n, 1 << i))
            {
                array[i] = i;
            }
        }
        return(array);
    }
Example #3
0
    public static void SimpleMath2()
    {
        var(N, M) = IOLibrary.ReadLong2();
        var m = (int)M;

        //循環節の長さ
        var rlist     = new List <int>();
        var remainder = 1;
        var s         = 0;
        var t         = 0;

        while (true)
        {
            var hasFound = false;
            for (s = 0; s < rlist.Count; s++)
            {
                if (rlist[s] == remainder)
                {
                    hasFound = true;
                    break;
                }
            }

            if (hasFound)
            {
                break;
            }

            rlist.Add(remainder);
            remainder = (remainder * 10) % m;
            if (remainder == 0)
            {
                break;
            }
            t++;
        }

        //循環節の長さ
        var digit = MathLibrary.Digits(N);

        var length = t - s + 1;



        var index = (N - 1) % length;
        var ans   = 0;

        Console.WriteLine(ans);
    }