Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Given five positive integers, their least majority multiple is the smallest positive integer that is divisible by at least three of them.
- //Your task is to write a program that for given distinct integers a, b, c, d and e, returns their least majority multiple.
- //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.
- //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.
- //Input
- //The input data is being read from the console.
- //The input data will consist of 5 lines.
- //The numbers a, b, c, d and e will each be on a single line.
- //The input data will always be valid and in the format described. There is no need to check it explicitly.
- //Output
- //The output data must be printed on the console.
- //On the only output line you must print the least majority multiple of the given numbers.
- //Constraints
- //• a, b, c, d and e will each be integer numbers between 1 and 100, inclusive.
- //• a, b, c, d and e will be distinct.
- //• Allowed working time for your program: 0.25 seconds.
- //• Allowed memory: 16 MB.
- using System;
- class Program
- {
- static void Main()
- {
- short a = short.Parse(Console.ReadLine());
- short b = short.Parse(Console.ReadLine());
- short c = short.Parse(Console.ReadLine());
- short d = short.Parse(Console.ReadLine());
- short e = short.Parse(Console.ReadLine());
- for (int i = 1; i < 970200; i++)
- {
- if (i % a == 0 && i % b == 0 && i % c == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % b == 0 && i % c == 0 && i % d == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % c == 0 && i % d == 0 && i % e == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % a == 0 && i % b == 0 && i % d == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % a == 0 && i % b == 0 && i % e == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % b == 0 && i % c == 0 && i % e == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % b == 0 && i % c == 0 && i % d == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % a == 0 && i % c == 0 && i % d == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % a == 0 && i % d == 0 && i % e == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % a == 0 && i % c == 0 && i % d == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % b == 0 && i % d == 0 && i % e == 0)
- {
- Console.WriteLine(i);
- break;
- }
- else if (i % a == 0 && i % c == 0 && i % e == 0)
- {
- Console.WriteLine(i);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment