Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
namespace PrimeDecomposition
{
class Program
{
static void Main(string[] args)
{
GetPrimes(12);
}
static List<int> GetPrimes(decimal n)
{
List<int> storage = new List<int>();
while (n > 1)
{
int i = 1;
while (true)
{
if (IsPrime(i))
{
if (((decimal)n / i) == Math.Round((decimal) n / i))
{
n /= i;
storage.Add(i);
break;
}
}
i++;
}
}
return storage;
}
static bool IsPrime(int n)
{
if (n <= 1) return false;
for (int i = 2; i <= Math.Sqrt(n); i++)
if (n % i == 0) return false;
return true;
}
}
}

View file

@ -0,0 +1,17 @@
using System.Collections.Generic;
namespace PrimeDecomposition
{
public class Primes
{
public List<int> FactorsOf(int n)
{
var factors = new List<int>();
for (var divisor = 2; n > 1; divisor++)
for (; n % divisor == 0; n /= divisor)
factors.Add(divisor);
return factors;
}
}