Numbers   (positive integers expressed in base ten)   that are (evenly) divisible by the number formed by the
first and last digit are known as   gapful numbers.


Evenly divisible   means divisible with   no   remainder.



All   one─   and two─digit   numbers have this property and are trivially excluded.   Only
numbers    ≥  100   will be considered for this Rosetta Code task.



Example

187   is a   gapful   number because it is evenly divisible by the
number   17   which is formed by the first and last decimal digits
of    187. 



About   7.46%   of positive integers are   gapful.



Task

   Generate and show all sets of numbers (below) on one line (horizontally) with a title,   here on this page
   Show the first   30   gapful numbers
   Show the first   15   gapful numbers    ≥           1,000,000
   Show the first   10   gapful numbers    ≥    1,000,000,000


Related tasks

   Harshad or Niven series.
   palindromic gapful numbers.
   largest number divisible by its digits.


Also see

   The OEIS entry:   A108343 gapful numbers.
   numbersaplenty gapful numbers


 
using System;
 
namespace GapfulNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("The first 30 gapful numbers are: ");
            /* Starting at 100, find 30 gapful numbers */
            FindGap(100, 30);
 
            Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ");
            FindGap(1000000, 15);
 
            Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ");
            FindGap(1000000000, 10);
 
            Console.Read();
        }
 
        public static int firstNum(int n)
        {
            /*Divide by ten until the leading digit remains.*/
            while (n >= 10)
            {
                n /= 10;
            }
            return (n);
        }
 
        public static int lastNum(int n)
        {
            /*Modulo gives you the last digit. */
            return (n % 10);
        }
 
        static void FindGap(int n, int gaps)
        {
            int count = 0;
            while (count < gaps)
            {
 
                /* We have to convert our first and last digits to strings to concatenate.*/
                string concat = firstNum(n).ToString() + lastNum(n).ToString();
                /* And then convert our concatenated string back to an integer. */
                int i = Convert.ToInt32(concat);
 
                /* Modulo with our new integer and output the result. */
                if (n % i == 0)
                {
                    Console.Write(n + " ");
                    count++;
                    n++;
                }
                else
                {
                    n++;
                    continue;
                }
            }
        }
    }
}
 
 
 