Tuesday, September 8, 2009

Easy - Just add 'em up

A= each non prime numbers between 1 and 1000
B= the lowest divisor (integer) for A
C= A * B

Example: If A = 10 B= 2 Then C = 20
And the sum of the C's up to A=10 is 83

What is the sum of all the C values for A up to 1000?

22 Comments:

Anonymous Wizard of Oz said...

C = 2 x sum of all even nos from 4 to 1000
+ 3 x sum of all nos divisible by 3 which are not divisible by 2
+ 5 x sum of all nos divisible by 5 which are not divisible by 2 or 3
and so on up to the highest prime less than the square root of 1000, which is 31.
The first term comes to 2 x 2 x 0.5 x 500 x 501 = 501,000
The second term comes to 3 x all odd multiples of 3 (i.e. all multiples less the even ones).
This as far as I've got time to take it today.
I have a growing suspicion that there's an easier way that I've overlooked.

September 8, 2009 11:51 PM  
Blogger Ragknot said...

To Wiz,

If I follow what you are doing, the sum of those where B=2 is 500996 which is 4 less than you got. I think you may have include 2*2=4, but 2 is a prime number.

September 9, 2009 12:29 AM  
Blogger Chris said...

Assuming 1 is not a prime: 1666891

September 9, 2009 4:48 AM  
Blogger Chris said...

Your example should have ended with 84.

September 9, 2009 5:11 AM  
Blogger Chris said...

This post has been removed by the author.

September 9, 2009 5:15 AM  
Blogger Ragknot said...

One is not considered a prime

September 9, 2009 5:27 AM  
Blogger Ragknot said...

This post has been removed by the author.

September 9, 2009 5:34 AM  
Blogger Ragknot said...

Once again Chris is correct.

September 9, 2009 5:34 AM  
Blogger Chris said...

My code:
Ctot=0;Ca=0;
For[A = 1, A <= 1000, A++, If[PrimeQ[A] == False, B = FactorInteger[A][[1, 1]]; Ca = A*B; Ctot += Ca]]
Print[Ctot]

PrimeQ[p] returns True if p is a prime, else False.
FactorInteger[n] returns a list of lists of factors and their multiplicity (in order low to high)
e.g. FactorInteger[18] => {{2,1},{3,2}] as 18 = 2^1 * 3^2
The [[1,1]] postfix operator returns the first 2.

I always consider 1 to be non-prime (and non-composite too ;) ). That's why I challenged your 83 result.

September 9, 2009 5:46 AM  
Blogger Chris said...

Phew! I'm glad you agree :)
That's easily the most complex Mathematica code that I've written. So thanks for the opportunity to take it for a spin.

My original code printed a lot of intermediate results so I could be sure I hadn't made any mistakes.

How did you do it? I assume not with AutoCAD. Greetz.

September 9, 2009 5:55 AM  
Blogger Chris said...

This post has been removed by the author.

September 11, 2009 1:40 AM  
Blogger Chris said...

Ragknot. A few mathematicians do say 1 is a prime. I simply wasn't sure if you did, because of example that ended with 83.

September 11, 2009 1:44 AM  
Blogger Watered Almonds said...

Cool. Here's the excel file.

http://www.2shared.com/file/7784880/8a923637/adding_non_prime_c.html

September 13, 2009 8:10 PM  
Anonymous Anonymous said...

[url=http://italtubi.com/tag/levitra-online/ ]generico levitra online [/url] bhCondivido pienamente il suo punto di vista. Ottima idea, sono d'accordo con lei. levitra generico

December 11, 2009 12:26 PM  
Anonymous Anonymous said...

This post has been removed by a blog administrator.

December 18, 2009 3:21 PM  
Anonymous Anonymous said...

This post has been removed by a blog administrator.

December 19, 2009 5:21 AM  
Anonymous Anonymous said...

This post has been removed by a blog administrator.

December 20, 2009 5:40 AM  
Anonymous Anonymous said...

This post has been removed by a blog administrator.

December 22, 2009 6:02 PM  
Anonymous Anonymous said...

This post has been removed by a blog administrator.

December 22, 2009 11:41 PM  
Anonymous Anonymous said...

This post has been removed by a blog administrator.

December 23, 2009 6:03 PM  
Anonymous Anonymous said...

This post has been removed by a blog administrator.

January 5, 2010 8:27 PM  
Anonymous Anonymous said...

This post has been removed by a blog administrator.

January 14, 2010 11:32 AM  

Post a Comment

Links to this post:

Create a Link

<< Home