include \Masm32\MasmBasic\Res\JBasic.inc ; ## builds in 32- or 64-bit mode with UAsm, ML, AsmC ##
Init ; OPT_64 1
Cls
PrintLine Chr$("This devilish program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
PrintLine "It shows pairs of numbers that match the formula m*n=666*(m+n)"
outer: inc rsi
xor rdi, rdi
inner: inc rdi
lea rax, [rsi+rdi]
imul rbx, rax, 666 ; (m+n)*666
mov rax, rdi
mul rsi ; m*n
cmp rax, rbx
jne @F
Print Str$("m*n: %i*%i\n", rsi, rdi)
@@: cmp rdi, 66666
jb inner
cmp rsi, 66666
jb outer
MsgBox 0, "Incredible, isn't it?", "Hi", MB_OK
EndOfCode
This devilish program was assembled with UAsm64 in 64-bit format.
It shows pairs of numbers that match the formula m*n=666*(m+n)
m*n: 675*49950
m*n: 678*37629
m*n: 684*25308
m*n: 693*17094
m*n: 702*12987
m*n: 703*12654
m*n: 720*8880
m*n: 740*6660
m*n: 747*6142
m*n: 774*4773
m*n: 777*4662
m*n: 814*3663
m*n: 828*3404
m*n: 888*2664
m*n: 990*2035
m*n: 999*1998
m*n: 1110*1665
m*n: 1332*1332
m*n: 1665*1110
m*n: 1998*999
m*n: 2035*990
m*n: 2664*888
m*n: 3404*828
m*n: 3663*814
m*n: 4662*777
m*n: 4773*774
m*n: 6142*747
m*n: 6660*740
m*n: 8880*720
m*n: 12654*703
m*n: 12987*702
m*n: 17094*693
m*n: 25308*684
m*n: 37629*678
m*n: 49950*675
Hi JJ!!
Perfect! That follow the rules (http://masm32.com/board/index.php?topic=10133.msg110597#msg110597) :thumbsup:
How you know initial RSI value?
Quote from: HSE on June 13, 2022, 04:56:09 AMHow you know initial RSI value?
Good question :bgrin:
Actually, I checked at the start of the program, directly after Init:
rax 1835008
rbx 5368722336
rcx 0
rdx 0
rsi 0
rdi 0
r8 1244488
r9 1245008
r10 2183232
r11 1243938
r12 0
r13 0
r14 0
r15 0
But it's an undocumented feature, so one should indeed add a
xor esi, esi :cool:
P.S. - there is an even more magic number, with 49 matching pairs:
This program was assembled with ml64 in 64-bit format.
It shows pairs of numbers that match the formula m*n=840*(m+n)
#1 m*n: 966*6440
#2 m*n: 980*5880
#3 m*n: 984*5740
#4 m*n: 987*5640
#5 m*n: 990*5544
#6 m*n: 1000*5250
#7 m*n: 1008*5040
#8 m*n: 1015*4872
#9 m*n: 1020*4760
#10 m*n: 1032*4515
#11 m*n: 1036*4440
#12 m*n: 1040*4368
#13 m*n: 1050*4200
#14 m*n: 1064*3990
#15 m*n: 1065*3976
#16 m*n: 1080*3780
#17 m*n: 1085*3720
#18 m*n: 1092*3640
#19 m*n: 1120*3360
#20 m*n: 1128*3290
#21 m*n: 1134*3240
#22 m*n: 1140*3192
#23 m*n: 1155*3080
#24 m*n: 1160*3045
#25 m*n: 1176*2940
#26 m*n: 1190*2856
#27 m*n: 1200*2800
#28 m*n: 1232*2640
#29 m*n: 1240*2604
#30 m*n: 1260*2520
#31 m*n: 1281*2440
#32 m*n: 1288*2415
#33 m*n: 1290*2408
#34 m*n: 1320*2310
#35 m*n: 1330*2280
#36 m*n: 1344*2240
#37 m*n: 1365*2184
#38 m*n: 1400*2100
#39 m*n: 1416*2065
#40 m*n: 1428*2040
#41 m*n: 1440*2016
#42 m*n: 1470*1960
#43 m*n: 1512*1890
#44 m*n: 1540*1848
#45 m*n: 1560*1820
#46 m*n: 1575*1800
#47 m*n: 1624*1740
#48 m*n: 1640*1722
#49 m*n: 1680*1680
Hi JJ!!
This is the ML64 version. It's faster because use things we know: minimum number is bigger than q, curve is symmetric, and first pair contain minimum and maximum number :biggrin:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include64\masm64rt.inc
.code
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
entry_point proc
local q : qword, sum : qword, check : qword
local pairs : qword, points : qword
local equals : qword, minimum : qword, maximum : qword
conout "This devilish program was assembled with ML64",lf
conout "It shows points of numbers that match the formula m*n="
mov rax, 840
mov q, rax
mov rcx, rax
inc rax
imul rax,rcx
mov maximum, rax
conout str$(q),"*(m+n)",lf,lf
mov pairs, 0
mov rax, q
shl rax, 1
mov equals, rax
mov rsi, q
outer:
inc rsi
mov rdi, minimum
inner:
inc rdi
lea rax, [rsi+rdi]
imul rax, q
mov rbx, rax ; (m+n)*q
mov rax, rdi
mul rsi ; m*n
cmp rax, rbx
jne @F
mov rax, rsi
add rax, rdi
mov sum, rax
mov rax, rsi
imul rax, rdi
idiv q
mov check, rax
conout "m*n : ", str$(rsi),"*",str$(rdi)," - ", str$(sum)," ", str$(check),lf
inc pairs
@@:
cmp rdi, maximum
jb inner
mov maximum, rdi
mov minimum, rsi
cmp rsi, equals
jb outer
mov rax, pairs
sub rax, 1
shl rax, 1
add rax, 1
mov points, rax ; curve is symmetric, only half is calculated
conout lf, "pairs = ",str$(pairs)," points = ",str$(points),lf,lf
waitkey
invoke ExitProcess,0
ret
entry_point endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end
LATER: - a little faster [H666C.zip (2.31 kB - downloaded 4 times.)]
- estimation of maximum
Quote from: HSE on June 13, 2022, 10:43:43 PM
This is the ML64 version. It's faster because use things we know: minimum number is bigger than q, curve is symmetric, and first pair contain minimum and maximum number :biggrin:
Excellent :thumbsup:
Try mov q, 10080 ;-)
P.S. Interesting patterns:
--- 32 items for magic 120 ---
--- 31 items for magic 168 ---
--- 37 items for magic 180 ---
--- 39 items for magic 210 ---
--- 39 items for magic 240 ---
--- 35 items for magic 252 ---
--- 34 items for magic 300 ---
--- 36 items for magic 330 ---
--- 36 items for magic 336 ---
--- 44 items for magic 360 ---
--- 31 items for magic 390 ---
--- 49 items for magic 420 ---
:thumbsup: Still running :biggrin:
Updated maximum number estimation, in previous post.
I'd like to see that, Hector, but I don't have access to my machine before Tuesday :sad:
Quote from: jj2007 on June 16, 2022, 04:12:25 AM
I don't have access to my machine
No problem, meanwhile you can check that manually: if q = 10080 then you only need 101,616,480 sums and multiplications just for first number :biggrin: :biggrin: :biggrin:
Is this topic full of diabolical solutions or is it just the mark of the beast ? :tongue:
Quote from: hutch-- on June 16, 2022, 11:11:19 AM
Is this topic full of diabolical solutions
Just one solution :biggrin:
Quote from: hutch-- on June 16, 2022, 11:11:19 AMor is it just the mark of the beast ? :tongue:
If JJ solve manually, I will be scared :biggrin: :biggrin: