Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _4.Nine_DigitMagicNumbers
- {
- using System;
- public class MagicNumbers
- {
- public static void Main(string[] args)
- {
- checked
- {
- int sum = int.Parse(Console.ReadLine());
- int diff = int.Parse(Console.ReadLine());
- bool foundMagicNumber = false;
- int a, b, c, d, e, f, g, h, i;
- for (a = 1; a <= 7; a++)
- {
- for (b = 1; b <= 7; b++)
- {
- for (c = 1; c <= 7; c++)
- {
- int firstNum = (a * 100) + (b * 10) + c;
- for (d = 1; d <= 7; d++)
- {
- for (e = 1; e <= 7; e++)
- {
- for (f = 1; f <= 7; f++)
- {
- int secondNum = (d * 100) + (e * 10) + f;
- if (secondNum - firstNum == diff)
- {
- for (g = 1; g <= 7; g++)
- {
- for (h = 1; h <= 7; h++)
- {
- for (i = 1; i <= 7; i++)
- {
- int thirdNum = (g * 100) + (h * 10) + i;
- int currentSum = a + b + c + d + e + f + g + h + i;
- if (currentSum == sum && thirdNum - secondNum == diff)
- {
- foundMagicNumber = true;
- Console.WriteLine("{0}{1}{2}", firstNum, secondNum, thirdNum);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (!foundMagicNumber)
- {
- Console.WriteLine("No");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement