Advertisement
veronikaaa86

TestNumbers

Jan 28th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Test
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int firstNum = int.Parse(Console.ReadLine());
  14.             int secondNum = int.Parse(Console.ReadLine());
  15.             int max = int.Parse(Console.ReadLine());
  16.  
  17.             int result = 0;
  18.             int counter = 0;
  19.             for (int i = firstNum; i >= 1; i--)
  20.             {
  21.                 for (int j = 1; j <= secondNum; j++)
  22.                 {
  23.                     counter++;
  24.                     result = result + ((i * j) * 3);
  25.                     if (result >= max)
  26.                     {
  27.                         break;
  28.                     }
  29.                 }
  30.                 if (result >= max)
  31.                 {
  32.                     break;
  33.                 }
  34.             }
  35.  
  36.             if (result >= max)
  37.             {
  38.                 Console.WriteLine($"{counter} combinations");
  39.                 Console.WriteLine($"Sum: {result} >= {max}");
  40.             }
  41.             else
  42.             {
  43.                 Console.WriteLine($"{counter} combinations");
  44.                 Console.WriteLine($"Sum: {result}");              
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement