Re: fastest way to add up a billion numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg73926] Re: fastest way to add up a billion numbers
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sat, 3 Mar 2007 01:05:20 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <es92b2$3oj$1@smc.vnet.net>
Raj wrote:
> hi!
>
> Could somebody tell me what would be the fastest way to add up a
> billion numbers(from 1 to 10^9 i.e the first billion numbers) in
> Mathematica?
>
> Ofcourse the answer is n(n+1)/2, but is there any other way in
> Mathematica other than the following one:
>
> Total@@Range[10^9]
Does not work on my 32-bit system.
In[2]:=
Total@@Range[10^9]//Timing
From In[1]:=
No more memory available.
Mathematica kernel has shut down.
Try quitting other applications and then retry.
> Thanks,
>
> Raj
>
>
What about Sum?
In[1]:=
Timing[Sum[i, {i, 10^9}]]
Out[1]=
{0.11 Second, 500000000500000000}
Regards,
Jean-Marc