BubaLazi

13TestNumbers

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