本文目录一览:
用delphi计算出1万以内的雷劈数算法
VAR
x,y:integer;
begin
for x:=1 to 10000 do begin
for y:=1 to 10000 do begin
if sqr(x+y) = strtoint(IntToStr(x)+inttostr(y)) then begin
mmo1.Lines.Add(IntToStr(x+y)+'^2='+'('+IntToStr(x)+'+'+IntToStr(y)+')^2='+IntToStr(x)+IntToStr(y));
end;
end;
end;
结果输出
9^2=(8+1)^2=81
45^2=(20+25)^2=2025
55^2=(30+25)^2=3025
297^2=(88+209)^2=88209
703^2=(494+209)^2=494209
2223^2=(494+1729)^2=4941729
2728^2=(744+1984)^2=7441984
4950^2=(2450+2500)^2=24502500
5050^2=(2550+2500)^2=25502500
7272^2=(5288+1984)^2=52881984
7777^2=(6048+1729)^2=60481729