using System;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        DateTime startTime = DateTime.Now;
        int totalCount = 0;
        object lockObject = new object();

        Parallel.For(1, 1000000001, () => 0, (number, state, localCount) =>
        {
            int sum = SumDigits(number);
            if (sum != 0 && number % sum == 0)
            {
                localCount++;
            }
            return localCount;
        },
        (localCount) =>
        {
            lock (lockObject)
            {
                totalCount += localCount;
            }
        });

        DateTime endTime = DateTime.Now;
        Console.WriteLine($"Количество хороших чисел: {totalCount}");
        Console.WriteLine($"Время выполнения: {(endTime - startTime).TotalSeconds} секунд");
    }

    static int SumDigits(int number)
    {
        int sum = 0;
        while (number > 0)
        {
            sum += number % 10;
            number /= 10;
        }
        return sum;
    }
}