Advertisement
skipter

C# Test Numbers - Magic num/ hardcore

Jun 3rd, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         int a = Math.Abs(int.Parse(Console.ReadLine()));
  7.         int b = Math.Abs(int.Parse(Console.ReadLine()));
  8.         int magicNumber = Math.Abs(int.Parse(Console.ReadLine()));
  9.         int sum = 0;
  10.         int totalCombinations = 0;
  11.         bool isMagicNumber = false;
  12.  
  13.         for (int i = a; i >= 1; i--)
  14.         {
  15.             for (int j = 1; j <= b; j++)
  16.             {
  17.                 if (sum >= magicNumber)
  18.                 {
  19.                     isMagicNumber = true;
  20.                     break;
  21.                 }
  22.                 else
  23.                 {
  24.                     totalCombinations++;
  25.                     sum += 3 * (i * j);
  26.                 }
  27.             }
  28.             if (sum >= magicNumber)
  29.             {
  30.                 isMagicNumber = true;
  31.                 break;
  32.             }
  33.         }
  34.  
  35.         Console.WriteLine("{0} combinations", totalCombinations);
  36.  
  37.         if (isMagicNumber)
  38.         {
  39.             Console.WriteLine("Sum: {0} >= {1}", sum, magicNumber);
  40.         }
  41.         else
  42.         {
  43.             Console.WriteLine("Sum: {0}", sum);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement