Register to reply 
Product of Primes! Programmers! 
Share this thread: 
#1
May2907, 04:53 AM

HW Helper
P: 3,348

Hey guys I really need some help as fast as you can give it to me. Basically I want to find a selection of 7 of the following numbers, which are primes. These selections have to add up to 100 exactly, and I know that there are 35 combinations.
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 I know that for 7 of these to add up to 100 2 needs to be one of the selections. What I need to be able to do is find the combination of 7 selections which add up to 100, that has the largest product! So if you know some programming, can you test all combinations? If not, do it another way? Please help asap! 


#2
May2907, 05:39 AM

Sci Advisor
HW Helper
P: 1,123

Well if you want to do it fast, then here's a way of reducing the amount of combinations involved, as you say you need to include 2, so you may as well drop that out of your list and try to sum to 98.
Furthermore, if you need 6 numbers (on this new list without 2), then on the new list the smallest 5 numbers adds up to 39, 98  39 = 59, so you may as well get rid of all numbers bigger than 59, leaving your new list as: 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 Testing all combinations might not be as difficult now, also consider if a rectangle has a fixed perimetre then its greatest area is a square, so I imagine looking for numbers which are close to each other will get you the greatest product, like: 31, 7, 11, 13, 17, 19 or: 23, 29, 11, 13, 17, 5 


#3
May2907, 06:10 AM

HW Helper
P: 3,348

*sigh* Ok I will try to list all the combinations of 6 numbers from your list that add up to 100. If anyone else could be so kind, could you guys post up any combinations you get listing the numbers in ascending order? I will post back when I get at least another 5.



#4
May2907, 06:22 AM

Sci Advisor
HW Helper
P: 1,123

Product of Primes! Programmers!
To be honest I think this might be the answer:
7, 11, 13, 17, 19, 31 Seems to have the lowest variance out of any combination, difficult to verify though, I might try typing up a naive program in C++ shortly and see how long it takes to compute. 


#5
May2907, 06:29 AM

HW Helper
P: 3,348

Thank you so so so much! I am make virtually no progress going through the manual combinations..



#6
May2907, 07:02 AM

Engineering
Sci Advisor
HW Helper
Thanks
P: 7,177

You can cut down the search a lot by using modular arithmetic.
All primes > 3 are equal to either 1 or 5 mod 6. 98 = 2 mod 6. The only possibilities that sum to 2 mod 6 are 1+1+1+1+5+5, 1+5+5+5+5+5, 3+1+1+1+1+1, 3+1+1+5+5+5 Consider the first option 1+1+1+1+5+5. The only sums of 4 primes equal to 1 mod 6 that are less than 98 are 7+13+19+31 = 70 7+13+19+37 = 76 7+13+19+43 = 82 So the 2 primes equal to 2 mod 6 must sum to 16, 22, or 28. The only options are 5+11=16 5+17=22 5+23=28 11+17=28 So we have 4 solutions, so far. The rest is left as an exercise for the reader. 


#7
May2907, 07:10 AM

HW Helper
P: 3,348

I'm afraid I don't understand...we are only allowed to use each prime once by the way. What do we have 4 solutions to??..sorry if i seem slow long day today..



#8
May2907, 07:41 AM

Sci Advisor
P: 1,132

You were right about there being 35, this is what i got:



#9
May2907, 07:46 AM

HW Helper
P: 3,348

Thanks Job !!! If anyone doesn't know a quicker way, ill go multiply these out on my calculator. Thanks!



#10
May2907, 07:53 AM

Sci Advisor
HW Helper
P: 1,123

Here's my quite badly written very naive code in C++
Then at the end gives the biggest product, with the primes used in the product, here's a screenshot of the output: http://zurtex.googlepages.com/primes1.jpg 


#11
May2907, 08:19 AM

HW Helper
P: 3,348

I Check back to this page too late :( wow Like 25 mins too late...we'll I get the same solution multiplying them out :) Thanks heaps :D!!



#12
May2907, 09:38 AM

Engineering
Sci Advisor
HW Helper
Thanks
P: 7,177

FWIW you don't need to work through every combination. The "1+5+5+5+5+5 mod 6" case gives one more possibility, so all the sets of primes that sum to 98 and do not include 3 are 5 7 11 13 19 43 5 7 13 19 23 31 5 7 13 17 19 37 5 11 13 17 23 29 7 11 13 17 19 31 The largest product is the 7*11*13*17*19*31 = 10023013. Suppose there was a larger product 3*p1*p2*p3*p4*p5 where 3+p1+p2+p3+p4+p5 = 98. Then p1*p2*p3*p4*p5 > 10023013/3 So the geometric mean of p1..p5 > (10023013/3)^{1/5} > 20 . But the arithmetic mean of p1..p5 > the geometric mean > 20 So p1+p2+p3+p4+p5 > 100, which is impossible. This is just to demonstrate that you dont HAVE to use a computer to solve this type of problem 


#13
May3007, 04:43 AM

HW Helper
P: 3,348

Hey guys I found the solution that my teacher said I should have used.
Zurtex I should have listened to your idea about the combination with the numbers closest together :) My teacher said to find the numbers with the smallest deviation, so basically i had to find 6 primes that are close t0 98/6 =16 and 2/3 Thanks tonnes guys! 


#14
May3007, 04:44 AM

HW Helper
P: 3,348




#15
May3007, 09:09 AM

P: 1,373

u could have just used matlab.



Register to reply 
Related Discussions  
Hadamard product to Matrix product transformation  General Math  3  
Monthly Food For Programmers  Programming & Computer Science  54  
Any Embeded System programmers out there?  Academic Guidance  0 