Guest User

Untitled

a guest
Jan 9th, 2023
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _05._Good_numbers
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.             int[] numbers = input
  12.                 .Split()
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.             int firstNumber = numbers[0];
  16.             int lastNummber = numbers[1];
  17.             int counter = 0;
  18.             bool isValid = true;
  19.             for (int i = firstNumber; i <= lastNummber; i++)
  20.             {
  21.                 int currentNum = i;
  22.                 while (currentNum>0)
  23.                 {
  24.                     int digit = currentNum % 10;
  25.  
  26.                     if (digit==0 || currentNum % digit == 0)
  27.                     {
  28.                         currentNum /= 10;
  29.                         continue;
  30.                     }
  31.                     else
  32.                     {
  33.                         isValid = false;
  34.                         break;
  35.                     }
  36.                 }
  37.                 if (isValid)
  38.                 {
  39.                     counter++;
  40.                 }
  41.                 else
  42.                 {
  43.                     continue;
  44.                 }
  45.             }
  46.             Console.WriteLine(counter);
  47.         }
  48.     }
  49. }
  50.  
Add Comment
Please, Sign In to add comment