Guest User

Good num

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