using System;namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args) { Console.WriteLine(foo(1)); }        static bool foo(int input)
        {
            if (input < 0)
            {
                return false;
            }            var i = (int)Math.Sqrt(input);            return i * i == input;
        }
    }
}

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args) { Console.WriteLine(foo(1)); }        static bool foo(uint input)
            {
                foreach (var i in getList(input))
                {
                    if (i > input)
                    {
                        return false;
                    }                if (i == input)
                    {
                        return true;
                    }
                }
                return false;
            }        static IEnumerable<uint> getList(uint input)
            {
                uint sum = 1;
                uint i = 1;            while (true)
                {
                    yield return sum;
                    i += 2;
                    sum += i;
                }
            }
        }
    }
      

  2.   

    ((1+(2n-1))/2)^2=1+3+5+............+2n-1
    反过来写吧
    1+3+5+............+ (2(n -1) -1)  + 2n-1
    = 1+3+5+............+ (2n -3)  + (2n-1)
    头尾两数为一组相加都等于2n,且不难看出数列共有n个数,共能组成多少队?
    = 2n * (n/2)
    = n^;
    证毕
      

  3.   

    正着写也一样啊
    ((1+(2n-1))/2)^2
    不就是n*n吗