尔冬橙

博客园 首页 新随笔 联系 订阅 管理

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 * 99.

Find the largest palindrome made from the product of two 3-digit numbers.

 2个两位数相乘得到的最大的回文数是9009,如:9009=91*99。

找出2个3位数相乘得到的最大的回文数。

static void Main(string[] args)
        {
            Int64 i, j,k,m;
            for (i = 999 * 999; i >= 100 * 100; i--)
            {
                if (isPrime(i) == true)
                {
                    for (j = 999; j >= 100; j--)
                    {
                        k = i % j;
                        m = i / j;
                        if (k == 0 && (m >= 100 && m <= 999))
                        {
                            Console.WriteLine("{0}*{1}={2}",j,m,i);
                            Console.ReadLine();
                            return;
                        }
                    }
                }
            }
        }
        public static bool isPrime(Int64 a)
        {
            char[] n = new char[20];
            int i,k=0;
            while(a>0)
            {
              n[k++] = (char)(a%10);
              a=a/10;
            }
            for(i =0;i<k/2;i++)
            {
              if(n[i]!=n[k-i-1]) return false;
            }
            return true;            
        }

结果:993*913=906609

posted on 2012-05-12 13:53  尔冬橙  阅读(310)  评论(0编辑  收藏  举报