Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out the closest possible combination of some given prime numbers to 10000?

Tags:

c#

algorithm

math

public int Partition1 {get;set;}
public int Partition1 {get;set;}

private void SetPartitions(List<int> primeNumbers)
{       
    this.Partition1 = // get the product of the prime numbers closest to 10000
    this.Partition2 = // get the product of the remaining prime numbers            
}

SetPartitions method accepts an array of prime numbers such as 2, 3, 5, 2851, 13.

In the above example, it should assign:

this.Partition1 = 2851 * 3; // which is 8553 and closest possible to 10000
this.Partition2 = 2 * 5 * 13;

How to implement the logic?

like image 416
The Light Avatar asked Nov 02 '11 22:11

The Light


People also ask

What is the closest prime number to 1000?

997 is the largest prime number between 1 to 1000. TrueTrue – 997 is the largest prime number between 1 to 1000.

How do you find the prime numbers from 100 to 1000?

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199.

How many factors do 10000 have?

The number 10000 has 23 factor not counting 1 or itself makeing it a square and maybe composite. Prime Factors for the number 10000 = (24 × 54) or(2 × 2 × 2 × 2 × 5 × 5 × 5 × 5).


1 Answers

Then go through each number from 10,000 to 2. For each of these, test to see if the prime factorization of the number is a subset of the given list. If it is, then we have found the answer.

Partition1 is the prime factors of the number. Partition2 is simply primeNumbers - Partition1.

Here's the psuedocode:

for n=10000 to 2
    factors = prime_factorization(n)

    if( factors is subset primeNumbers ) {
        partition1 = factors
        partition2 = primeNumbers - factors
        return (partition1,partition2)
    }
like image 76
tskuzzy Avatar answered Sep 28 '22 09:09

tskuzzy