Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Nine_Digit_Magic_Numbers
- {
- class MagicNumbers
- {
- static void Main(string[] args)
- {
- int sumOfNum = int.Parse(Console.ReadLine());
- int difference = int.Parse(Console.ReadLine());
- int counter = 0;
- for (int i1 = 1; i1 <= 7; i1++)
- {
- for (int i2 = 1; i2 <= 7; i2++)
- {
- for (int i3 = 1; i3 <= 7; i3++)
- {
- for (int i4 = 1; i4 <= 7; i4++)
- {
- for (int i5 = 1; i5 <= 7; i5++)
- {
- for (int i6 = 1; i6 <= 7; i6++)
- {
- int firstThree = int.Parse("" + i1 + i2 + i3);
- int secondThree = int.Parse("" + i4 + i5 + i6);
- if (secondThree - firstThree == difference && secondThree > firstThree)
- {
- for (int i7 = 1; i7 <= 7; i7++)
- {
- for (int i8 = 1; i8 <= 7; i8++)
- {
- for (int i9 = 1; i9 <= 7; i9++)
- {
- if ((i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9) == sumOfNum)
- {
- int lastThree = int.Parse("" + i7 + i8 + i9);
- if (secondThree - firstThree == difference
- && lastThree - secondThree == difference
- && lastThree > secondThree && secondThree > firstThree)
- {
- Console.WriteLine("" + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9);
- counter++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (counter == 0)
- {
- Console.WriteLine("No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement