Click here to Skip to main content
15,888,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello sir,
i have one textbox, one button, and one gridview control when i was enter the number in textbox for 1000 and click on the button i need to display all the prime factor numbers in gridview colums (i.e semi,tri,quad,quint,sext and upto 15th prime factor numbers)

if anyone know this please help me to solve it..............................

i dont know how to caluclate prime factors up to 15thprime factor
Posted
Updated 11-Mar-13 19:44pm
v7
Comments
Andreas Gieriet 11-Mar-13 8:03am    
What is the problem?
You (don't) know what prime factors are?
You (don't) know how to calculate prime factors starting from 2?
You (don't) know how to make the GUI?
You (don't) know how to trigger the function from the button?
You (don't) know how to readout the textbox value?
You (don't) know how to populate the gridview?
You (don't) know how to decompose a problem into digestable parts?
You (don't) know how to research for problem solutions?
So, what is your problem?
We do not do your homework here.
If you don't manage or are not willing to do it yourself, seek for another subject to study.
Cheers
Andi
Andreas Gieriet 12-Mar-13 17:42pm    
See my solution#3.

A simple Google search will find you lots of articles that explain how to find prime numbers. And there are also a number in the CodeProject articles section[^].
 
Share this answer
 
Assuming that there is an upper bound on the largest prime (you said something about the 15th prime which would be 47: see here[^], you can easily construct an array containing all the allowed primes. Then starting from the smallest prime (2) towards the largest (47 if my assumption was correct) you iterate over said array and try if the number to be factorized can be divided by the current prime number with a modulo of zero (no remainder).

0. If the number cannot be divided without remainder by the current prime goto 3.
1. If the number can be divided by the current prime without remainder, set the number to be tested to the number divided by the prime and set the exponent of the current prime to one.
2. As long as the division stays without remainder do 1.
3. Choose the next prime from the array and continue with 0.

4. The iteration must stop when the number to factorized becomes one, because then the factorization is done. In case my assumption was correct you can also stop the factorization if you run out of primes. The reduced number will then be the remainder of the factorization under the set limitations.

Interesting side note why one is the termination condition:

All numbers can be expressed by a set of tuples {(n0,m0),..., (ni, mi) } where the first part mi of the tuple is the prime number and the second part mi is the exponent for that prime. The factorized number can thus be expressed as

m0m0 * ... * nimi

for all the prime numbers there are. Thankfully we don't have to include all the prime numbers there are (and we couldn't do so either even if we wanted as their number is infinite), because any number raised to the power of zero is one an and thus will not change the product in any way.

Since the number 1 cannot be factorized, the exponents for all possible primes are 0 giving a one for each prime number0 . The product of all infinite number of primes raised to the power of zero is 1 then again 1.


I hope this wasn't to confusing.

Regards,

— Manfred
 
Share this answer
 
v3
A possible solution in pseudo code:
1. get the number of entries to calculate (e.g. 1000)
2. build the "Sieve of Eratosthenes" up to the square root of that number
3. calculate the prime factors of each number from 2 to that given number
   by looking up factors in the pre-calculated Sieve of Eratosthenes

Sieve of Eratosthenes: see Wikipedia[^].

Calculating the factors of one number N in pseudo code:
1. end if N is less than 2
2. find in the Sieve of Eratosthenes an entry that gives no rest if N is devided by that entry
3. if not such entry is found N is the factor
4. else, the entry is the factor
5. divide N by the factor and take that new N to step 1.

Cheers
Andi
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900