Sum multiples of 3 and 5: Difference between revisions

Line 9:
'''Extra credit:''' do this efficiently for ''n'' = 1e20 or higher.
<br><br>
 
=={{header|360 Assembly}}==
<lang 360asm>
* Sum multiples of 3 and 5
SUM35 CSECT
USING SUM35,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
STM R14,R12,12(R13) save previous context
ST R13,4(R15) link backward
ST R15,8(R13) link forward
LR R13,R15 set addressability
LA R9,1 n=1
LA R7,7 do j=7 to 1 step -1
LOOPJ MH R9,=H'10' n=n*10
LR R10,R9 n
BCTR R10,0 n-1
ZAP SUM,=PL8'0' sum=0
LA R6,3 i=3
DO WHILE=(CR,R6,LE,R10) do i=3 to n-1
LR R4,R6 i
SRDA R4,32
D R4,=F'3' i/3
LTR R4,R4 if mod(i,3)=0
BZ CVD
LR R4,R6 i
SRDA R4,32
D R4,=F'5' i/5
LTR R4,R4 if mod(i,5)=0
BNZ ITERI
CVD CVD R6,IP ip=p
AP SUM,IP sum=sum+i
ITERI LA R6,1(R6) i++
ENDDO , enddo i
XDECO R9,PG n
MVC PG+15(16),EM16 load mask
ED PG+15(16),SUM packed dec (PL8) to char (CL16)
XPRNT PG,L'PG print
BCT R7,LOOPJ enddo j
L R13,4(0,R13) restore previous savearea pointer
LM R14,R12,12(R13) restore previous context
XR R15,R15 rc=0
BR R14 exit
SUM DS PL8
IP DS PL8
EM16 DC X'40202020202020202020202020202120' mask CL16 15num
PG DC CL80'123456789012 : 1234567890123456'
YREGS
END SUM35
</lang>
{{out}}
<pre>
10 : 23
100 : 2318
1000 : 233168
10000 : 23331668
100000 : 2333316668
1000000 : 233333166668
10000000 : 23333331666668
</pre>
 
 
=={{header|ALGOL 68}}==
1,392

edits