Advertisement
sylviapsh

Least Majority Multiple

Dec 27th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. class LeastMajorityMultiple
  3. {
  4.   static void Main()
  5.   {
  6.     //Telerik Academy
  7.     //Given five positive integers, their least majority multiple is the smallest positive integer that is divisible by at least three of them.
  8.     //Your task is to write a program that for given distinct integers a, b, c, d and e, returns their least majority multiple.
  9.     //For example if we have 1, 2, 3, 4 and 5 the majority multiple of the given five numbers is 4 because it is divisible by 1, 2, and 4.
  10.  
  11.     int[] numsArray = new int[5];
  12.  
  13.     for (int counter = 0; counter < 5; counter++)
  14.     {
  15.       int inputNum = int.Parse(Console.ReadLine());
  16.       numsArray[counter] = inputNum;
  17.     }
  18.  
  19.     for (int i = 1; true; i++)
  20.     {
  21.       int count = 0;
  22.  
  23.       for (int index = 0; index < 5; index++)
  24.       {
  25.         if (i % numsArray[index] == 0)
  26.         {
  27.           count++;
  28.         }
  29.       }
  30.  
  31.       if (count >= 3)
  32.       {
  33.         Console.WriteLine(i);
  34.         break;
  35.       }
  36.     }
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement