Jump to content

Digit fifth powers: Difference between revisions

add fermat, freebasic, gwbasic
m (→‎{{header|Factor}}: attribution)
(add fermat, freebasic, gwbasic)
Line 8:
<br><br>
 
=={{header|BASIC}}==
==={{header|FreeBASIC}}===
<lang freebasic>function dig5( n as uinteger ) as uinteger
dim as string ns = str(n)
dim as uinteger ret = 0
for i as ubyte = 2 to len(ns)
ret += val(mid(ns,i,1))^5
next i
return ret
end function
 
dim as uinteger i, sum = 0
 
for i = 0 to 999999
if i = dig5(i) then
print i
sum += i
end if
next i
 
print "Their sum is ", sum</lang>
{{out}}<pre>
4150
4151
54748
92727
93084
194979
Their sum is 443839</pre>
==={{header|GW-BASIC}}===
<lang gwbasic>10 SUM! = 0
20 FOR I! = 2 TO 999999!
30 GOSUB 80
40 IF R! = I! THEN SUM! = SUM! + I! : PRINT I!
50 NEXT I!
60 PRINT "Total = ",SUM
70 END
80 N$ = STR$(I)
90 R! = 0
100 FOR J = 1 TO LEN(N$)
110 D = VAL(MID$(N$,J,1))
120 R! = R! + D*D*D*D*D
130 NEXT J
140 RETURN
</lang>
{{out}}<pre>
4150
4151
54748
92727
93084
194979
Total = 443839</pre>
=={{header|Fermat}}==
<lang fermat>Func Sumfp(n) = if n<10 then Return(n^5) else Return((n|10)^5 + Sumfp(n\10)) fi.;
sum:=0;
for i=2 to 999999 do if i=Sumfp(i) then sum:=sum+i; !!i fi od;
!!('The sum was ', sum );</lang>
{{out}}<pre>
4150
4151
54748
92727
93084
194979
The sum was 443839</pre>
 
=={{header|Factor}}==
781

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.