clearvars
for coeff=1:8
for n=2:1000
s=sum(1:coeff:coeff*n-coeff+1); sr=round(sqrt(s)); if sr^2==s
disp([coeff,n,sr])
break
end
end
end
finds
1 8 6
2 2 2
3 81 99
4 25 35
5 6 9
6 9 15
7 2 3
The 8th formula does not result in a square; all the others do.
For part 2:
The formulae result in nth triangular number, nth square, nth pentagonal number, etc. One can work out a formula for the nth k-gonal number:
((k-2)*(n^2)-(k-4)*n)/2
Then:
clearvars
g=vpa(2305843008139952128);
syms n
for k=3:10
vpasolve((((k-2)*(n^2)-(k-4)*n)/2==g),n)
end
finds
ans =
-2147483648.0
2147483647.0
ans =
-1518500249.6344714555912614710542
1518500249.6344714555912614710542
ans =
-1239850261.7977777392390120644691
1239850262.1311110725723453978024
ans =
-1073741823.5
1073741824.0
ans =
-960383882.97583926156636299038065
960383883.57583926156636299038065
ans =
-876706527.55764268403274142666611
876706528.22430935069940809333277
ans =
-811672524.76612772996865662217737
811672525.48041344425437090789165
ans =
-759250124.44223572788823855698375
759250125.19223572788823855698375
where only the first and fourth formulae have integral solutions for n: 2147483647 or 1073741824.
Analytic solutions for this can be found in the online Spring 2024 issue of BENT Brain Ticklers.
|