3 ms·
I'm getting bigger numbers from a very quick script -- am I missing something? digitalsum(999^75) = 999 999^75 = 9277086733900014664321616999375876127716937
by sonofgod 8y ago
I'm getting bigger numbers from a very quick script -- am I missing something?
digitalsum(999^75) = 999
999^75 = 927708673390001466432161699937587612771693772928727827334425528520027513591277141564708297244305734237029149442895264407211992619276548532187236223108524403378301874096420069132958960388059297398105903507708174617522225074999
- sonofgod 8y agodef test(x, y, debug=True): num = x**y digitalsum = sum(int(a) for a in str(num)) if x == digitalsum and debug: print x, y, num return x == digitalsum for i in range(1,1000): for j in range(1,100): if test(i, j): print i, j
- lmcarreiro 8y agoAfter you calc X^Y, when you will calc X^(Y+1), doesn't it worth to calc using the previous result (X^Y)*X instead of another power X^(Y+1) ?
- deleted 8y ago[deleted]
- kazinator 8y agoYou will find here that the run-time is swamped by the digit breakdown and summing, so that exponentiation versus accumulated product doesn't make a palpable difference.
- kazinator 8y agoTXR lisp: This is the TXR Lisp interactive listener of TXR 203. Quit with :quit or Ctrl-D on empty line. Ctrl-X ? for cheatsheet. 1> (each ((x (range 2 1000))) ;; 1 is uninteresting (each ((y (range 1 100))) (let ((z (expt x y))) (when (= x (sum (digits z))) (put-line `@x @y`))))) 2 1 3 1 4 1 5 1 [...] 963 69 964 75 964 78 991 71 999 75
- kazinator 8y agoUsing successive multiplication instead of exponent operation: 6> (each ((x (range 2 1000))) (each ((y (range 1 100)) ;; needed just for the put-line (z [giterate true (op * x) x])) (when (= x (sum (digits z))) (put-line `@x @y`)))) (Makes no difference; run time is vastly dominated by the contribution of the (sum (digits z)) business.)