Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Least Common Multiple of 2 or more numbers.
//Least Common Multiple of 2 or more numbers. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Net; using System.IO; using System.Numerics; namespace Rextester { public static class Program { static BigInteger GreatestCommonFactor(BigInteger a, BigInteger b) { while (b != 0) { BigInteger temp = b; b = a % b; a = temp; } return a; } static BigInteger LeastCommonMultiple(BigInteger a, BigInteger b) { BigInteger gcf = GreatestCommonFactor(a, b); if (gcf == 0) return 0; return (a / gcf) * b; } static BigInteger[] ToBigInteger(string[] arr) { BigInteger[] result = new BigInteger[arr.Length]; for (int i = 0; i < arr.Length; i++) { result[i] = BigInteger.Parse(arr[i]); } return result; } public static void Main(string[] args) { BigInteger[] numbers = ToBigInteger(Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); if (numbers.Length > 0) { BigInteger result = numbers[0]; for (int i = 1; i < numbers.Length; i++) { result = LeastCommonMultiple(result, numbers[i]); } Console.WriteLine(result.ToString()); } else { Console.WriteLine("Error: no numbers entered"); } } } }
run
|
edit
|
history
|
help
1
adxcsxsd
Use ConcurrentQueue and ConcurrentDictionary with TPL (Simple example)
|= Caching
unsorted array which has a number in the majority (a number appears more than 50% in the array
Delegate test lambda
HourCouter
Factory Method Design Pattern
SpiltStringBetweenSpecialCharacters
Rotation String
Planet-D