Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: Euler probl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 10 Topic 4044 of 4065
Post > Topic >>

Re: Euler problem #48

by Bernd Paysan <bernd.paysan@[EMAIL PROTECTED] > May 8, 2008 at 11:22 AM

Marcel Hendrix wrote:

> INCLUDE ../bignum/factor.frt

If you have a 64 bit Forth (and I know you have ;-), you don't need
bignums
for that. All intermediate results have at most 20 digits, and therefore
easily fit in a 128 bit number; the sum with at most 13 digits fits in a
64
bit number. This one should be faster (how much depends on how efficient
your gs^mod actually is). In Gforth with a 2GHz Athlon64, it takes about
1.5ms to run 1000t. I guess iForth64 should do it in less than 1ms, even
when the division for the modulus might be the limiting factor.

\ sum of the last 10 digits of n^n for n=1..1000

Cell 8 < [IF] .( Needs a 64 bit Forth!) cr true abort  [THEN]

&10000000000 Constant mod#

: *mod ( a b -- c )  um* mod# um/mod drop ;

: **mod ( x n -- n )  >r 1 swap
    BEGIN  r@[EMAIL PROTECTED]
 1 and  IF  tuck *mod swap  THEN
        r> 2/ dup  WHILE  >r dup *mod  REPEAT
    2drop ;

: e48 ( n -- g )
    0 swap 1+ 1 DO
        I dup **mod +
    LOOP  mod# mod ;

: Euler48 ( -- )  
         CR ." The last ten digits of the series "
         ." 1^1 + 2^2 + 3^3 + ... + 1000^1000 are " 1000 e48 . cr ;

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/




 10 Posts in Topic:
Euler problem #48
mhx@[EMAIL PROTECTED] (M  2008-05-07 22:55:35 
Re: Euler problem #48
Bernd Paysan <bernd.pa  2008-05-08 11:22:15 
Re: Euler problem #48
anton@[EMAIL PROTECTED]   2008-05-08 10:28:32 
Re: Euler problem #48
Thomas Pornin <pornin@  2008-05-08 14:18:40 
Re: Euler problem #48
Bernd Paysan <bernd.pa  2008-05-08 16:33:41 
Re: Euler problem #48
Albert van der Horst <  2008-05-09 02:08:35 
Re: Euler problem #48
Albert van der Horst <  2008-05-08 17:00:16 
Re: Euler problem #48
William James <w_a_x_m  2008-05-09 08:44:42 
[SPOILER] Re: Euler problem #48
mhx@[EMAIL PROTECTED] (M  2008-05-09 19:13:05 
Re: [SPOILER] Re: Euler problem #48
Albert van der Horst <  2008-05-09 22:07:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 5:29:03 CDT 2008.