Advertisement
Guest User

TestNum

a guest
Sep 25th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 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 HW2Softuni
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int m = int.Parse(Console.ReadLine());
  15.             int boundary = int.Parse(Console.ReadLine());
  16.             int totalSum = 0;
  17.             int result = 0;
  18.             int numberOfCombinations = 0;
  19.             if (n >= 1 && n <= 100 && m >= 1 && m <= 100 && boundary>=1 && boundary<=1000000)
  20.             {
  21.                 for (int i = n; i >= 1; i--)
  22.                 {
  23.                     for (int j = 1; j <= m; j++)
  24.                     {
  25.                         result = (i * j) * 3;
  26.                         totalSum += result;
  27.                         numberOfCombinations++;
  28.                         if (totalSum >= boundary)
  29.                         {
  30.                             break;
  31.                         }
  32.  
  33.                     }
  34.                     if (totalSum >= boundary)
  35.                     {
  36.                         break;
  37.                     }
  38.                 }
  39.  
  40.                 Console.WriteLine($"{numberOfCombinations} combinations");
  41.                 if (totalSum > boundary)
  42.                 {
  43.                     Console.WriteLine($"Sum: {totalSum} >= {boundary}");
  44.                 }
  45.                 else
  46.                 {
  47.                     Console.WriteLine($"Sum: {totalSum}");
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement