jkonova

Untitled

Aug 10th, 2021
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TheSongOfTheWheels
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int M = int.Parse(Console.ReadLine());
  10.  
  11.             int combinationsCount = 0;
  12.             string password = "";
  13.             int sum = 0;
  14.  
  15.             if ((M >= 4) && (M <= 144))
  16.             {
  17.                 for (int first = 1; first <= 9; first++)
  18.                 {
  19.                     for (int second = 1; second <= 9; second++)
  20.                     {
  21.                         for (int third = 1; third <= 9; third++)
  22.                         {
  23.                             for (int fourth = 1; fourth <= 9; fourth++)
  24.                             {
  25.                                 sum = (first * second) + (third * fourth);
  26.                                 if (first < second && third > fourth && sum == M)
  27.                                 {
  28.                                     combinationsCount++;
  29.                                     Console.Write($"{first}{second}{third}{fourth} ");
  30.                                     if (combinationsCount == 4)
  31.                                     {
  32.                                         password = $"{first}{second}{third}{fourth} ";
  33.                                     }
  34.                                 }
  35.                             }
  36.                         }
  37.                     }
  38.                 }
  39.                 if (combinationsCount >= 4)
  40.                 {
  41.                     Console.WriteLine();
  42.                     Console.WriteLine($"Password: {password}");
  43.                 }
  44.                 else
  45.                 {
  46.                     Console.WriteLine("No!");
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment