stkirov

Problem 2 – Least Majority Multiple

Oct 26th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.41 KB | None | 0 0
  1. //Given five positive integers, their least majority multiple is the smallest positive integer that is divisible by at least three of them.
  2. //Your task is to write a program that for given distinct integers a, b, c, d and e, returns their least majority multiple.
  3. //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.
  4. //Another example: if we have 30, 42, 70, 35 and 90 the answer will be 210, because it is divisible by 30, 42, 70, and 35 - four out of five numbers, which is a majority.
  5. //Input
  6. //The input data is being read from the console.
  7. //The input data will consist of 5 lines.
  8. //The numbers a, b, c, d and e will each be on a single line.
  9. //The input data will always be valid and in the format described. There is no need to check it explicitly.
  10. //Output
  11. //The output data must be printed on the console.
  12. //On the only output line you must print the least majority multiple of the given numbers.
  13. //Constraints
  14. //•   a, b, c, d and e will each be integer numbers between 1 and 100, inclusive.
  15. //•   a, b, c, d and e will be distinct.
  16. //•   Allowed working time for your program: 0.25 seconds.
  17. //•   Allowed memory: 16 MB.
  18.  
  19.  
  20. using System;
  21.  
  22. class Program
  23. {
  24.     static void Main()
  25.     {
  26.         short a = short.Parse(Console.ReadLine());
  27.         short b = short.Parse(Console.ReadLine());
  28.         short c = short.Parse(Console.ReadLine());
  29.         short d = short.Parse(Console.ReadLine());
  30.         short e = short.Parse(Console.ReadLine());
  31.  
  32.         for (int i = 1; i < 970200; i++)
  33.         {
  34.             if (i % a == 0 && i % b == 0 && i % c == 0)
  35.             {
  36.                 Console.WriteLine(i);
  37.                 break;
  38.             }
  39.             else if (i % b == 0 && i % c == 0 && i % d == 0)
  40.             {
  41.                 Console.WriteLine(i);
  42.                 break;
  43.             }
  44.             else if (i % c == 0 && i % d == 0 && i % e == 0)
  45.             {
  46.                 Console.WriteLine(i);
  47.                 break;
  48.             }
  49.             else if (i % a == 0 && i % b == 0 && i % d == 0)
  50.             {
  51.                 Console.WriteLine(i);
  52.                 break;
  53.             }
  54.             else if (i % a == 0 && i % b == 0 && i % e == 0)
  55.             {
  56.                 Console.WriteLine(i);
  57.                 break;
  58.             }
  59.             else if (i % b == 0 && i % c == 0 && i % e == 0)
  60.             {
  61.                 Console.WriteLine(i);
  62.                 break;
  63.             }
  64.             else if (i % b == 0 && i % c == 0 && i % d == 0)
  65.             {
  66.                 Console.WriteLine(i);
  67.                 break;
  68.             }
  69.             else if (i % a == 0 && i % c == 0 && i % d == 0)
  70.             {
  71.                 Console.WriteLine(i);
  72.                 break;
  73.             }
  74.             else if (i % a == 0 && i % d == 0 && i % e == 0)
  75.             {
  76.                 Console.WriteLine(i);
  77.                 break;
  78.             }
  79.             else if (i % a == 0 && i % c == 0 && i % d == 0)
  80.             {
  81.                 Console.WriteLine(i);
  82.                 break;
  83.             }
  84.             else if (i % b == 0 && i % d == 0 && i % e == 0)
  85.             {
  86.                 Console.WriteLine(i);
  87.                 break;
  88.             }
  89.             else if (i % a == 0 && i % c == 0 && i % e == 0)
  90.             {
  91.                 Console.WriteLine(i);
  92.                 break;
  93.             }
  94.  
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment