using System.Collections.Generic;
static bool IsPrime(int num)
if (num < 2) return false;
for (int i = 2; i * i <= num; i++)
if (num % i == 0) return false;
static List<int> GetPrimes(int n)
List<int> primes = new List<int>();
for (int i = 2; i <= n; i++)
static void FindPrimePartitions(int target, List<int> primes, List<int> currentPartition, int start)
int sum = currentPartition.Sum();
Console.Write(target + " = " + string.Join(" + ", currentPartition));
Console.WriteLine($" ({currentPartition.Count} numbers)");
if (sum > target) return;
for (int i = start; i < primes.Count; i++)
currentPartition.Add(primes[i]);
FindPrimePartitions(target, primes, currentPartition, i + 1);
currentPartition.RemoveAt(currentPartition.Count - 1);
Console.Write("Please enter an integer: ");
if (int.TryParse(Console.ReadLine(), out int input))
List<int> primes = GetPrimes(input);
List<int> currentPartition = new List<int>();
FindPrimePartitions(input, primes, currentPartition, 0);
Console.WriteLine($"{input} has {CountPrimePartitions(input, primes, 0)} unique prime partitions!");
Console.WriteLine("Invalid input. Please enter a valid integer.");
static int CountPrimePartitions(int target, List<int> primes, int start)
if (target == 0) return 1;
if (target < 0 || start >= primes.Count) return 0;
for (int i = start; i < primes.Count; i++)
count += CountPrimePartitions(target - primes[i], primes, i + 1);