' Generates Most Perfect Franklin Magic Squares of order 16, Magic Sum 2056
' Tested with Office 2007 under Windows 7
Sub MgcSqr16b()
Dim a(256), b(256), c(256)
y = MsgBox("Locked", vbCritical, "Routine MgcSqr16b")
End
n2 = 0: n9 = 0
m1 = 1: m2 = 256: s1 = 2056
' Generate data
Sheets("Klad1").Select
t1 = Timer
For j256 = 88 To 88 'a(256)
If b(j256) = 0 Then b(j256) = j256: c(256) = j256 Else GoTo 2560
a(256) = j256
For j255 = 131 To 131 'a(255)
If b(j255) = 0 Then b(j255) = j255: c(255) = j255 Else GoTo 2550
a(255) = j255
For j254 = 125 To 125 'a(254)
If b(j254) = 0 Then b(j254) = j254: c(254) = j254 Else GoTo 2540
a(254) = j254
jj = 254
a(253) = 514 - a(254) - a(255) - a(256): j = 253: GoSub 3000: If fl1 = 1 Then GoTo 2540
For j252 = 86 To 86 'a(252)
If b(j252) = 0 Then b(j252) = j252: c(252) = j252 Else GoTo 2520
a(252) = j252
For j251 = 129 To 129 'a(251)
If b(j251) = 0 Then b(j251) = j251: c(251) = j251 Else GoTo 2510
a(251) = j251
jj = 251
a(250) = -a(252) + a(254) + a(256): j = 250: GoSub 3000: If fl1 = 1 Then GoTo 2510
a(249) = 514 - a(251) - a(254) - a(256): j = 249: GoSub 3000: If fl1 = 1 Then GoTo 2510
For j248 = 120 To 120 'a(248)
If b(j248) = 0 Then b(j248) = j248: c(248) = j248 Else GoTo 2480
a(248) = j248
For j247 = 163 To 163 'a(247)
If b(j247) = 0 Then b(j247) = j247: c(247) = j247 Else GoTo 2470
a(247) = j247
jj = 247
a(246) = -a(248) + a(254) + a(256): j = 246: GoSub 3000: If fl1 = 1 Then GoTo 2470
a(245) = 514 - a(247) - a(254) - a(256): j = 245: GoSub 3000: If fl1 = 1 Then GoTo 2470
For j244 = 118 To 118 'a(244)
If b(j244) = 0 Then b(j244) = j244: c(244) = j244 Else GoTo 2440
a(244) = j244
For j243 = 161 To 161 'a(243)
If b(j243) = 0 Then b(j243) = j243: c(243) = j243 Else GoTo 2430
a(243) = j243
jj = 243
a(242) = -a(244) + a(254) + a(256): j = 242: GoSub 3000: If fl1 = 1 Then GoTo 2430
a(241) = 514 - a(243) - a(254) - a(256): j = 241: GoSub 3000: If fl1 = 1 Then GoTo 2430
For j240 = 121 To 121 'a(240)
If b(j240) = 0 Then b(j240) = j240: c(240) = j240 Else GoTo 2400
a(240) = j240
jj = 240
a(239) = 514 - a(240) - a(255) - a(256): j = 239: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(238) = a(240) - a(254) + a(256): j = 238: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(237) = -a(240) + a(254) + a(255): j = 237: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(236) = a(240) - a(252) + a(256): j = 236: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(235) = 514 - a(240) - a(251) - a(256): j = 235: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(234) = a(240) + a(252) - a(254): j = 234: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(233) = -a(240) + a(251) + a(254): j = 233: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(232) = a(240) - a(248) + a(256): j = 232: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(231) = 514 - a(240) - a(247) - a(256): j = 231: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(230) = a(240) + a(248) - a(254): j = 230: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(229) = -a(240) + a(247) + a(254): j = 229: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(228) = a(240) - a(244) + a(256): j = 228: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(227) = 514 - a(240) - a(243) - a(256): j = 227: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(226) = a(240) + a(244) - a(254): j = 226: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(225) = -a(240) + a(243) + a(254): j = 225: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(224) = 257 - a(254): j = 224: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(223) = -257 + a(254) + a(255) + a(256): j = 223: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(222) = 257 - a(256): j = 222: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(221) = 257 - a(255): j = 221: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(220) = 257 + a(252) - a(254) - a(256): j = 220: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(219) = -257 + a(251) + a(254) + a(256): j = 219: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(218) = 257 - a(252): j = 218: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(217) = 257 - a(251): j = 217: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(216) = 257 + a(248) - a(254) - a(256): j = 216: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(215) = -257 + a(247) + a(254) + a(256): j = 215: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(214) = 257 - a(248): j = 214: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(213) = 257 - a(247): j = 213: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(212) = 257 + a(244) - a(254) - a(256): j = 212: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(211) = -257 + a(243) + a(254) + a(256): j = 211: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(210) = 257 - a(244): j = 210: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(209) = 257 - a(243): j = 209: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(208) = 257 - a(240) + a(254) - a(256): j = 208: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(207) = 257 + a(240) - a(254) - a(255): j = 207: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(206) = 257 - a(240): j = 206: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(205) = -257 + a(240) + a(255) + a(256): j = 205: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(204) = 257 - a(240) - a(252) + a(254): j = 204: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(203) = 257 + a(240) - a(251) - a(254): j = 203: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(202) = 257 - a(240) + a(252) - a(256): j = 202: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(201) = -257 + a(240) + a(251) + a(256): j = 201: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(200) = 257 - a(240) - a(248) + a(254): j = 200: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(199) = 257 + a(240) - a(247) - a(254): j = 199: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(198) = 257 - a(240) + a(248) - a(256): j = 198: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(197) = -257 + a(240) + a(247) + a(256): j = 197: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(196) = 257 - a(240) - a(244) + a(254): j = 196: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(195) = 257 + a(240) - a(243) - a(254): j = 195: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(194) = 257 - a(240) + a(244) - a(256): j = 194: GoSub 3000: If fl1 = 1 Then GoTo 2540
a(193) = -257 + a(240) + a(243) + a(256): j = 193: GoSub 3000: If fl1 = 1 Then GoTo 2540
For j192 = 72 To 72 'a(192)
If b(j192) = 0 Then b(j192) = j192: c(192) = j192 Else GoTo 1920
a(192) = j192
jj = 192
a(191) = -a(192) + a(255) + a(256): j = 191: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(190) = a(192) + a(254) - a(256): j = 190: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(189) = 514 - a(192) - a(254) - a(255): j = 189: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(188) = a(192) + a(252) - a(256): j = 188: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(187) = -a(192) + a(251) + a(256): j = 187: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(186) = a(192) - a(252) + a(254): j = 186: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(185) = 514 - a(192) - a(251) - a(254): j = 185: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(184) = a(192) + a(248) - a(256): j = 184: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(183) = -a(192) + a(247) + a(256): j = 183: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(182) = a(192) - a(248) + a(254): j = 182: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(181) = 514 - a(192) - a(247) - a(254): j = 181: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(180) = a(192) + a(244) - a(256): j = 180: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(179) = -a(192) + a(243) + a(256): j = 179: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(178) = a(192) - a(244) + a(254): j = 178: GoSub 3000: If fl1 = 1 Then GoTo 1920
a(177) = 514 - a(192) - a(243) - a(254): j = 177: GoSub 3000: If fl1 = 1 Then GoTo 1920
For j176 = 105 To 105 'a(176)
If b(j176) = 0 Then b(j176) = j176: c(176) = j176 Else GoTo 1760
a(176) = j176
jj = 176
a(175) = 514 - a(176) - a(255) - a(256): j = 175: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(174) = a(176) - a(254) + a(256): j = 174: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(173) = -a(176) + a(254) + a(255): j = 173: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(172) = a(176) - a(252) + a(256): j = 172: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(171) = 514 - a(176) - a(251) - a(256): j = 171: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(170) = a(176) + a(252) - a(254): j = 170: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(169) = -a(176) + a(251) + a(254): j = 169: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(168) = a(176) - a(248) + a(256): j = 168: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(167) = 514 - a(176) - a(247) - a(256): j = 167: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(166) = a(176) + a(248) - a(254): j = 166: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(165) = -a(176) + a(247) + a(254): j = 165: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(164) = a(176) - a(244) + a(256): j = 164: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(163) = 514 - a(176) - a(243) - a(256): j = 163: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(162) = a(176) + a(244) - a(254): j = 162: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(161) = -a(176) + a(243) + a(254): j = 161: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(160) = 257 - a(192) - a(254) + a(256): j = 160: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(159) = -257 + a(192) + a(254) + a(255): j = 159: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(158) = 257 - a(192): j = 158: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(157) = 257 + a(192) - a(255) - a(256): j = 157: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(156) = 257 - a(192) + a(252) - a(254): j = 156: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(155) = -257 + a(192) + a(251) + a(254): j = 155: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(154) = 257 - a(192) - a(252) + a(256): j = 154: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(153) = 257 + a(192) - a(251) - a(256): j = 153: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(152) = 257 - a(192) + a(248) - a(254): j = 152: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(151) = -257 + a(192) + a(247) + a(254): j = 151: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(150) = 257 - a(192) - a(248) + a(256): j = 150: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(149) = 257 + a(192) - a(247) - a(256): j = 149: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(148) = 257 - a(192) + a(244) - a(254): j = 148: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(147) = -257 + a(192) + a(243) + a(254): j = 147: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(146) = 257 - a(192) - a(244) + a(256): j = 146: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(145) = 257 + a(192) - a(243) - a(256): j = 145: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(144) = 257 - a(176) + a(254) - a(256): j = 144: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(143) = 257 + a(176) - a(254) - a(255): j = 143: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(142) = 257 - a(176): j = 142: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(141) = -257 + a(176) + a(255) + a(256): j = 141: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(140) = 257 - a(176) - a(252) + a(254): j = 140: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(139) = 257 + a(176) - a(251) - a(254): j = 139: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(138) = 257 - a(176) + a(252) - a(256): j = 138: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(137) = -257 + a(176) + a(251) + a(256): j = 137: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(136) = 257 - a(176) - a(248) + a(254): j = 136: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(135) = 257 + a(176) - a(247) - a(254): j = 135: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(134) = 257 - a(176) + a(248) - a(256): j = 134: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(133) = -257 + a(176) + a(247) + a(256): j = 133: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(132) = 257 - a(176) - a(244) + a(254): j = 132: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(131) = 257 + a(176) - a(243) - a(254): j = 131: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(130) = 257 - a(176) + a(244) - a(256): j = 130: GoSub 3000: If fl1 = 1 Then GoTo 1760
a(129) = -257 + a(176) + a(243) + a(256): j = 129: GoSub 3000: If fl1 = 1 Then GoTo 1760
For j128 = m1 To m2 'a(128)
If b(j128) = 0 Then b(j128) = j128: c(128) = j128 Else GoTo 1280
a(128) = j128
jj = 128
a(127) = -a(128) + a(255) + a(256): j = 127: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(126) = a(128) + a(254) - a(256): j = 126: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(125) = 514 - a(128) - a(254) - a(255): j = 125: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(124) = a(128) + a(252) - a(256): j = 124: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(123) = -a(128) + a(251) + a(256): j = 123: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(122) = a(128) - a(252) + a(254): j = 122: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(121) = 514 - a(128) - a(251) - a(254): j = 121: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(120) = a(128) + a(248) - a(256): j = 120: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(119) = -a(128) + a(247) + a(256): j = 119: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(118) = a(128) - a(248) + a(254): j = 118: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(117) = 514 - a(128) - a(247) - a(254): j = 117: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(116) = a(128) + a(244) - a(256): j = 116: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(115) = -a(128) + a(243) + a(256): j = 115: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(114) = a(128) - a(244) + a(254): j = 114: GoSub 3000: If fl1 = 1 Then GoTo 1280
a(113) = 514 - a(128) - a(243) - a(254): j = 113: GoSub 3000: If fl1 = 1 Then GoTo 1280
For j112 = m1 To m2 'a(112)
If b(j112) = 0 Then b(j112) = j112: c(112) = j112 Else GoTo 1120
a(112) = j112
jj = 112
a(111) = 514 - a(112) - a(255) - a(256): j = 111: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(110) = a(112) - a(254) + a(256): j = 110: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(109) = -a(112) + a(254) + a(255): j = 109: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(108) = a(112) - a(252) + a(256): j = 108: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(107) = 514 - a(112) - a(251) - a(256): j = 107: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(106) = a(112) + a(252) - a(254): j = 106: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(105) = -a(112) + a(251) + a(254): j = 105: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(104) = a(112) - a(248) + a(256): j = 104: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(103) = 514 - a(112) - a(247) - a(256): j = 103: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(102) = a(112) + a(248) - a(254): j = 102: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(101) = -a(112) + a(247) + a(254): j = 101: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(100) = a(112) - a(244) + a(256): j = 100: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(99) = 514 - a(112) - a(243) - a(256): j = 99: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(98) = a(112) + a(244) - a(254): j = 98: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(97) = -a(112) + a(243) + a(254): j = 97: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(96) = 257 - a(128) - a(254) + a(256): j = 96: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(95) = -257 + a(128) + a(254) + a(255): j = 95: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(94) = 257 - a(128): j = 94: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(93) = 257 + a(128) - a(255) - a(256): j = 93: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(92) = 257 - a(128) + a(252) - a(254): j = 92: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(91) = -257 + a(128) + a(251) + a(254): j = 91: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(90) = 257 - a(128) - a(252) + a(256): j = 90: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(89) = 257 + a(128) - a(251) - a(256): j = 89: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(88) = 257 - a(128) + a(248) - a(254): j = 88: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(87) = -257 + a(128) + a(247) + a(254): j = 87: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(86) = 257 - a(128) - a(248) + a(256): j = 86: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(85) = 257 + a(128) - a(247) - a(256): j = 85: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(84) = 257 - a(128) + a(244) - a(254): j = 84: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(83) = -257 + a(128) + a(243) + a(254): j = 83: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(82) = 257 - a(128) - a(244) + a(256): j = 82: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(81) = 257 + a(128) - a(243) - a(256): j = 81: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(80) = 257 - a(112) + a(254) - a(256): j = 80: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(79) = 257 + a(112) - a(254) - a(255): j = 79: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(78) = 257 - a(112): j = 78: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(77) = -257 + a(112) + a(255) + a(256): j = 77: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(76) = 257 - a(112) - a(252) + a(254): j = 76: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(75) = 257 + a(112) - a(251) - a(254): j = 75: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(74) = 257 - a(112) + a(252) - a(256): j = 74: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(73) = -257 + a(112) + a(251) + a(256): j = 73: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(72) = 257 - a(112) - a(248) + a(254): j = 72: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(71) = 257 + a(112) - a(247) - a(254): j = 71: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(70) = 257 - a(112) + a(248) - a(256): j = 70: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(69) = -257 + a(112) + a(247) + a(256): j = 69: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(68) = 257 - a(112) - a(244) + a(254): j = 68: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(67) = 257 + a(112) - a(243) - a(254): j = 67: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(66) = 257 - a(112) + a(244) - a(256): j = 66: GoSub 3000: If fl1 = 1 Then GoTo 1120
a(65) = -257 + a(112) + a(243) + a(256): j = 65: GoSub 3000: If fl1 = 1 Then GoTo 1120
For j64 = m1 To m2 'a(64)
If b(j64) = 0 Then b(j64) = j64: c(64) = j64 Else GoTo 640
a(64) = j64
jj = 64
a(63) = -a(64) + a(255) + a(256): j = 63: GoSub 3000: If fl1 = 1 Then GoTo 640
a(62) = a(64) + a(254) - a(256): j = 62: GoSub 3000: If fl1 = 1 Then GoTo 640
a(61) = 514 - a(64) - a(254) - a(255): j = 61: GoSub 3000: If fl1 = 1 Then GoTo 640
a(60) = a(64) + a(252) - a(256): j = 60: GoSub 3000: If fl1 = 1 Then GoTo 640
a(59) = -a(64) + a(251) + a(256): j = 59: GoSub 3000: If fl1 = 1 Then GoTo 640
a(58) = a(64) - a(252) + a(254): j = 58: GoSub 3000: If fl1 = 1 Then GoTo 640
a(57) = 514 - a(64) - a(251) - a(254): j = 57: GoSub 3000: If fl1 = 1 Then GoTo 640
a(56) = a(64) + a(248) - a(256): j = 56: GoSub 3000: If fl1 = 1 Then GoTo 640
a(55) = -a(64) + a(247) + a(256): j = 55: GoSub 3000: If fl1 = 1 Then GoTo 640
a(54) = a(64) - a(248) + a(254): j = 54: GoSub 3000: If fl1 = 1 Then GoTo 640
a(53) = 514 - a(64) - a(247) - a(254): j = 53: GoSub 3000: If fl1 = 1 Then GoTo 640
a(52) = a(64) + a(244) - a(256): j = 52: GoSub 3000: If fl1 = 1 Then GoTo 640
a(51) = -a(64) + a(243) + a(256): j = 51: GoSub 3000: If fl1 = 1 Then GoTo 640
a(50) = a(64) - a(244) + a(254): j = 50: GoSub 3000: If fl1 = 1 Then GoTo 640
a(49) = 514 - a(64) - a(243) - a(254): j = 49: GoSub 3000: If fl1 = 1 Then GoTo 640
For j48 = m1 To m2 'a(48)
If b(j48) = 0 Then b(j48) = j48: c(48) = j48 Else GoTo 480
a(48) = j48
jj = 48
a(47) = 514 - a(48) - a(255) - a(256): j = 47: GoSub 3000: If fl1 = 1 Then GoTo 480
a(46) = a(48) - a(254) + a(256): j = 46: GoSub 3000: If fl1 = 1 Then GoTo 480
a(45) = -a(48) + a(254) + a(255): j = 45: GoSub 3000: If fl1 = 1 Then GoTo 480
a(44) = a(48) - a(252) + a(256): j = 44: GoSub 3000: If fl1 = 1 Then GoTo 480
a(43) = 514 - a(48) - a(251) - a(256): j = 43: GoSub 3000: If fl1 = 1 Then GoTo 480
a(42) = a(48) + a(252) - a(254): j = 42: GoSub 3000: If fl1 = 1 Then GoTo 480
a(41) = -a(48) + a(251) + a(254): j = 41: GoSub 3000: If fl1 = 1 Then GoTo 480
a(40) = a(48) - a(248) + a(256): j = 40: GoSub 3000: If fl1 = 1 Then GoTo 480
a(39) = 514 - a(48) - a(247) - a(256): j = 39: GoSub 3000: If fl1 = 1 Then GoTo 480
a(38) = a(48) + a(248) - a(254): j = 38: GoSub 3000: If fl1 = 1 Then GoTo 480
a(37) = -a(48) + a(247) + a(254): j = 37: GoSub 3000: If fl1 = 1 Then GoTo 480
a(36) = a(48) - a(244) + a(256): j = 36: GoSub 3000: If fl1 = 1 Then GoTo 480
a(35) = 514 - a(48) - a(243) - a(256): j = 35: GoSub 3000: If fl1 = 1 Then GoTo 480
a(34) = a(48) + a(244) - a(254): j = 34: GoSub 3000: If fl1 = 1 Then GoTo 480
a(33) = -a(48) + a(243) + a(254): j = 33: GoSub 3000: If fl1 = 1 Then GoTo 480
a(32) = 257 - a(64) - a(254) + a(256): j = 32: GoSub 3000: If fl1 = 1 Then GoTo 480
a(31) = -257 + a(64) + a(254) + a(255): j = 31: GoSub 3000: If fl1 = 1 Then GoTo 480
a(30) = 257 - a(64): j = 30: GoSub 3000: If fl1 = 1 Then GoTo 480
a(29) = 257 + a(64) - a(255) - a(256): j = 29: GoSub 3000: If fl1 = 1 Then GoTo 480
a(28) = 257 - a(64) + a(252) - a(254): j = 28: GoSub 3000: If fl1 = 1 Then GoTo 480
a(27) = -257 + a(64) + a(251) + a(254): j = 27: GoSub 3000: If fl1 = 1 Then GoTo 480
a(26) = 257 - a(64) - a(252) + a(256): j = 26: GoSub 3000: If fl1 = 1 Then GoTo 480
a(25) = 257 + a(64) - a(251) - a(256): j = 25: GoSub 3000: If fl1 = 1 Then GoTo 480
a(24) = 257 - a(64) + a(248) - a(254): j = 24: GoSub 3000: If fl1 = 1 Then GoTo 480
a(23) = -257 + a(64) + a(247) + a(254): j = 23: GoSub 3000: If fl1 = 1 Then GoTo 480
a(22) = 257 - a(64) - a(248) + a(256): j = 22: GoSub 3000: If fl1 = 1 Then GoTo 480
a(21) = 257 + a(64) - a(247) - a(256): j = 21: GoSub 3000: If fl1 = 1 Then GoTo 480
a(20) = 257 - a(64) + a(244) - a(254): j = 20: GoSub 3000: If fl1 = 1 Then GoTo 480
a(19) = -257 + a(64) + a(243) + a(254): j = 19: GoSub 3000: If fl1 = 1 Then GoTo 480
a(18) = 257 - a(64) - a(244) + a(256): j = 18: GoSub 3000: If fl1 = 1 Then GoTo 480
a(17) = 257 + a(64) - a(243) - a(256): j = 17: GoSub 3000: If fl1 = 1 Then GoTo 480
a(16) = 257 - a(48) + a(254) - a(256): j = 16: GoSub 3000: If fl1 = 1 Then GoTo 480
a(15) = 257 + a(48) - a(254) - a(255): j = 15: GoSub 3000: If fl1 = 1 Then GoTo 480
a(14) = 257 - a(48): j = 14: GoSub 3000: If fl1 = 1 Then GoTo 480
a(13) = -257 + a(48) + a(255) + a(256): j = 13: GoSub 3000: If fl1 = 1 Then GoTo 480
a(12) = 257 - a(48) - a(252) + a(254): j = 12: GoSub 3000: If fl1 = 1 Then GoTo 480
a(11) = 257 + a(48) - a(251) - a(254): j = 11: GoSub 3000: If fl1 = 1 Then GoTo 480
a(10) = 257 - a(48) + a(252) - a(256): j = 10: GoSub 3000: If fl1 = 1 Then GoTo 480
a(9) = -257 + a(48) + a(251) + a(256): j = 9: GoSub 3000: If fl1 = 1 Then GoTo 480
a(8) = 257 - a(48) - a(248) + a(254): j = 8: GoSub 3000: If fl1 = 1 Then GoTo 480
a(7) = 257 + a(48) - a(247) - a(254): j = 7: GoSub 3000: If fl1 = 1 Then GoTo 480
a(6) = 257 - a(48) + a(248) - a(256): j = 6: GoSub 3000: If fl1 = 1 Then GoTo 480
a(5) = -257 + a(48) + a(247) + a(256): j = 5: GoSub 3000: If fl1 = 1 Then GoTo 480
a(4) = 257 - a(48) - a(244) + a(254): j = 4: GoSub 3000: If fl1 = 1 Then GoTo 480
a(3) = 257 + a(48) - a(243) - a(254): j = 3: GoSub 3000: If fl1 = 1 Then GoTo 480
a(2) = 257 - a(48) + a(244) - a(256): j = 2: GoSub 3000: If fl1 = 1 Then GoTo 480
a(1) = -257 + a(48) + a(243) + a(256): j = 1: GoSub 3000: If fl1 = 1 Then GoTo 480
n9 = n9 + 1
GoSub 2650 'Print results (squares)
' GoSub 2645 'Print results (selected numbers
jj = 48: GoSub 3050 'Reset b() and c()
480 Next j48
jj = 64: GoSub 3050 'Reset b() and c()
640 Next j64
jj = 112: GoSub 3050 'Reset b() and c()
1120 Next j112
jj = 128: GoSub 3050 'Reset b() and c()
1280 Next j128
jj = 176: GoSub 3050 'Reset b() and c()
1760 Next j176
jj = 192: GoSub 3050 'Reset b() and c()
1920 Next j192
jj = 240: GoSub 3050 'Reset b() and c()
2400 Next j240
jj = 243: GoSub 3050 'Reset b() and c()
2430 Next j243
b(c(244)) = 0: c(244) = 0
2440 Next j244
jj = 247: GoSub 3050 'Reset b() and c()
2470 Next j247
b(c(248)) = 0: c(248) = 0
2480 Next j248
jj = 251: GoSub 3050 'Reset b() and c()
2510 Next j251
b(c(252)) = 0: c(252) = 0
2520 Next j252
jj = 254: GoSub 3050 'Reset b() and c()
2540 Next j254
b(c(255)) = 0: c(255) = 0
2550 Next j255
b(c(256)) = 0: c(256) = 0
2560 Next j256
t2 = Timer
t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s1)
y = MsgBox(t10, 0, "Routine MgcSqr16b")
End
' Print results (selected numbers)
2645 For i1 = 1 To 256
Cells(n9, i1).Value = a(i1)
Next i1
Return
' Print results (squares)
2650 n2 = n2 + 1
If n2 = 3 Then
n2 = 1: k1 = k1 + 17: k2 = 0
Else
If n9 > 1 Then k2 = k2 + 17
End If
Cells(k1 + 1, k2 + 1).Select
i3 = 0
For i1 = 1 To 16
For i2 = 1 To 16
i3 = i3 + 1
Cells(k1 + i1, k2 + i2).Value = a(i3)
Next i2
Next i1
Return
' Exclude identical solutions and solutions out of range
3000 fl1 = 0
If a(j) <= 0 Or a(j) > 256 Then fl1 = 1: GoTo 3010
If b(a(j)) = 0 Then b(a(j)) = a(j): c(j) = a(j) Else fl1 = 1
3010 If fl1 = 1 Then 'Reset b() and c()
For i = j + 1 To jj
b(c(i)) = 0: c(i) = 0
Next i
End If
Return
' Reset b() and c() after completion loop
3050 For i = j To jj
b(c(i)) = 0: c(i) = 0
Next i
Return
End Sub