Definition at line 8 of file NumberTheory.cs.
◆ Factorize()
static IEnumerable<int> BGC.Mathematics.NumberTheory.Factorize |
( |
int |
number | ) |
|
|
inlinestatic |
Definition at line 82 of file NumberTheory.cs.
92 while (number % 2 == 0)
98 foreach (
int prime
in PrimesUpTo((
int)Math.Sqrt(number)))
100 while (number % prime == 0)
static IEnumerable< int > PrimesUpTo(int number)
◆ LeastCommonMultiple()
static int BGC.Mathematics.NumberTheory.LeastCommonMultiple |
( |
IEnumerable< int > |
numbers | ) |
|
|
inlinestatic |
Definition at line 10 of file NumberTheory.cs.
12 if (numbers.Count() == 1)
14 return numbers.First();
static IEnumerable< int > MergedFactorization(IEnumerable< int > numbers)
◆ MergedFactorization()
Definition at line 20 of file NumberTheory.cs.
22 if (numbers == null || numbers.Count() == 0)
27 if (numbers.Count() == 1)
29 foreach (
int factor
in Factorize(numbers.First()))
37 int[] nums = numbers.ToArray();
39 for (
int i = 0; i < nums.Length; i++)
42 while (nums[i] % 2 == 0)
46 for (
int j = 0; j < nums.Length; j++)
58 foreach (
int prime
in PrimesUpTo((
int)Math.Sqrt(max)))
60 for (
int i = 0; i < nums.Length; i++)
63 while (nums[i] % prime == 0)
67 for (
int j = 0; j < nums.Length; j++)
70 if (nums[j] % prime == 0)
static IEnumerable< int > Factorize(int number)
static IEnumerable< int > PrimesUpTo(int number)
◆ PrimesUpTo()
static IEnumerable<int> BGC.Mathematics.NumberTheory.PrimesUpTo |
( |
int |
number | ) |
|
|
inlinestatic |
Definition at line 118 of file NumberTheory.cs.
128 BitArray primeField =
new BitArray(number,
true);
129 primeField.Set(0,
false);
130 primeField.Set(1,
false);
140 for (
int i = 3; i * i < number; i += 2)
142 if (primeField.Get(i))
152 for (
int j = i * i; j < number; j += 2 * i)
154 primeField.Set(j,
false);
The documentation for this class was generated from the following file: