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?
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:
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.
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.
Assuming 1 is not a prime: 1666891
Your example should have ended with 84.
This post has been removed by the author.
One is not considered a prime
This post has been removed by the author.
Once again Chris is correct.
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.
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.
This post has been removed by the author.
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.
Cool. Here's the excel file.
http://www.2shared.com/file/7784880/8a923637/adding_non_prime_c.html
[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
This post has been removed by a blog administrator.
This post has been removed by a blog administrator.
This post has been removed by a blog administrator.
This post has been removed by a blog administrator.
This post has been removed by a blog administrator.
This post has been removed by a blog administrator.
This post has been removed by a blog administrator.
This post has been removed by a blog administrator.
Post a Comment
Links to this post:
Create a Link
<< Home