/// <summary>
        /// <paramref name="n"/> の約数を返します。
        /// </summary>
        public static long[] Divisor(long n)
        {
            if (n == 1)
            {
                return new long[] { 1 }
            }
            ;

            var left  = new SimpleList <long>();
            var right = new SimpleList <long>();

            left.Add(1);
            right.Add(n);

            for (long i = 2, d = Math.DivRem(n, i, out long amari);

                 i <= d;
                 i++, d = Math.DivRem(n, i, out amari))
            {
                if (amari == 0)
                {
                    left.Add(i);
                    if (i != d)
                    {
                        right.Add(d);
                    }
                }
            }
            right.Reverse();
            var res = new long[left.Count + right.Count];

            left.CopyTo(res, 0);
            right.CopyTo(res, left.Count);
            return(res);
        }
Example #2
0
 public SimpleList<int> GetIndexes()
 {
     var current = this;
     var indexes = new SimpleList<int>();
     while (current != null)
     {
         indexes.Add(current.Index);
         current = current.Parent;
     }
     indexes.Reverse();
     return indexes;
 }
Example #3
0
        }  //EndMethod

        public IEnumerable <int> SimpleListReverse()
        {
            return(SimpleListItems.Reverse());
        }  //EndMethod