Abundant odd numbers: Difference between revisions

Added X86 assembly language example.
(Add CLU)
(Added X86 assembly language example.)
Line 6,387:
The first abundant odd number above one billion is:
1000000575 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 + 11025 + 90703 + 272109 + 453515 + 634921 + 816327 + 1360545 + 1904763 + 2267575 + 3174605 + 4081635 + 4444447 + 5714289 + 6802725 + 9523815 + 13333341 + 15873025 + 20408175 + 22222235 + 28571445 + 40000023 + 47619075 + 66666705 + 111111175 + 142857225 + 200000115 + 333333525 = 1083561009
</pre>
 
=={{header|X86 Assembly}}==
Assemble with: tasm and tlink /t
<lang asm> .model tiny
.code
.486
org 100h
;ebp=counter, edi=Num, ebx=Div, esi=Sum
start: xor ebp, ebp ;odd abundant number counter:= 0
mov edi, 3 ;Num:= 3
ab10: mov ebx, 3 ;Div:= 3
mov esi, 1 ;Sum:= 1
ab20: mov eax, edi ;Quot:= Num/Div
cdq ;edx:= 0
div ebx ;eax(q):edx(r):= edx:eax/ebx
cmp ebx, eax ;if Div > Quot then quit loop
jge ab50
test edx, edx ;if remainder = 0 then
jne ab30
add esi, ebx ; Sum:= Sum + Div
cmp ebx, eax ; if Div # Quot then
je ab30
add esi, eax ; Sum:= Sum + Quot
ab30: add ebx, 2 ;Div:= Div+2 (only check odd Nums)
jmp ab20 ;loop
ab50:
cmp esi, edi ;if Sum > Num then
jle ab80
inc ebp ; counter:= counter+1
cmp ebp, 25 ; if counter<=25 or counter>=1000 then
jle ab60
cmp ebp, 1000
jl ab80
ab60: mov eax, edi ; print Num
call numout
mov al, ' ' ; print spaces
int 29h
int 29h
mov eax, esi ; print Sum
call numout
mov al, 0Dh ; carriage return
int 29h
mov al, 0Ah ; line feed
int 29h
cmp ebp, 1000 ; if counter = 1000 then
jne ab65
mov edi, 1000000001-2 ; Num:= 1,000,000,001 - 2
ab65: cmp edi, 1000000000 ; if Num > 1,000,000,000 then exit
jg ab90
ab80: add edi, 2 ;Num:= Num+2 (only check odd Nums)
jmp ab10 ;loop
ab90: ret
 
;Print signed integer in eax with commas, e.g: 12,345,010
numout: xor ecx, ecx ;digit counter:= 0
no00: cdq ;edx:= 0
mov ebx, 10 ;Num:= Num/10
div ebx ;eax(q):edx(r):= edx:eax/ebx
push edx ;remainder = least significant digit
inc ecx ;count digit
test eax, eax ;if Num # 0 then NumOut(Num)
je no20
call no00
no20: pop eax ;print digit + '0'
add al, '0'
int 29h
dec ecx ;un-count digit
je no30 ;if counter # 0 and
mov al, cl ; if remainder(counter/3) = 0 then
aam 3
jne no30
mov al, ',' ; print ','
int 29h
no30: ret
end start</lang>
{{out}}
<pre>
945 975
1,575 1,649
2,205 2,241
2,835 2,973
3,465 4,023
4,095 4,641
4,725 5,195
5,355 5,877
5,775 6,129
5,985 6,495
6,435 6,669
6,615 7,065
6,825 7,063
7,245 7,731
7,425 7,455
7,875 8,349
8,085 8,331
8,415 8,433
8,505 8,967
8,925 8,931
9,135 9,585
9,555 9,597
9,765 10,203
10,395 12,645
11,025 11,946
492,975 519,361
1,000,000,575 1,083,561,009
</pre>
 
291

edits