public class Solution
    {
        public IList<int> PowerfulIntegers(int x, int y, int bound)
        {            
            var list = new List<int>();
            for (int i = 0; i < bound; i++)
            {
                for (int j = 0; j < bound; j++)
                {
                    var num =
                        Math.Pow((double)x, (double)i)
                        +
                        Math.Pow((double)y, (double)j);
                    if (num <= bound)
                    {
                        list.Add((int)num);
                    }
                    else
                    {
                        if (j == 0)
                        {
                            return list.Distinct().OrderBy(a => a).ToList();
                        }
                        else
                        {
                            break;//换行
                        }
                    }
                }
            }
            return list.Distinct().OrderBy(a => a).ToList();
        }
    }

 

posted on 2019-01-22 11:02  Sempron2800+  阅读(119)  评论(0编辑  收藏  举报