Created
January 19, 2018 05:02
-
-
Save unilecs/b6313f7042a6d785af302d2ec90a8c49 to your computer and use it in GitHub Desktop.
Задача 63: НОК - наименьшее общее кратное
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Numerics; | |
public class Program | |
{ | |
public static int GCD(int a, int b) | |
{ | |
return (b == 0) ? a : GCD(b, a % b); | |
} | |
public static void GetNOK(int[] arr) | |
{ | |
for (int i = 0; i < arr.Length; i++) | |
{ | |
for (int j = i + 1; j < arr.Length; j++) | |
{ | |
int tmp = GCD(arr[i], arr[j]); | |
arr[j] /= tmp; | |
} | |
} | |
BigInteger res = BigInteger.One; | |
for (int i = 0; i < arr.Length; i++) | |
{ | |
var bigInt = new BigInteger(arr[i]); | |
res = BigInteger.Multiply(res, bigInt); | |
} | |
Console.WriteLine(string.Format("Answer = {0}", res)); | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
var arr = new int[] { 2, 12, 6, 24, 3 }; | |
GetNOK(arr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment