Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created January 19, 2018 05:02
Show Gist options
  • Save unilecs/b6313f7042a6d785af302d2ec90a8c49 to your computer and use it in GitHub Desktop.
Save unilecs/b6313f7042a6d785af302d2ec90a8c49 to your computer and use it in GitHub Desktop.
Задача 63: НОК - наименьшее общее кратное
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