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
C# Programming Exercise 3
Find duplicates in a given integer array
Lp2
shuffle2
Date format display
Fórum ➡ Get all combinations for ▶different◀ Id's ( GroupBy version ) ♦
Approximate_exp_13112020
6
New easy way to start lightweight threads
Recursive 3