Talk:Steady squares: Difference between revisions
Content added Content deleted
Line 21: | Line 21: | ||
end; |
end; |
||
</lang> |
</lang> |
||
:Note also that it must end in 1,5 or 6 (not 0 as any number ending in 0 squared ends with twice as many zeros).--[[User:Nigel Galloway|Nigel Galloway]] ([[User talk:Nigel Galloway|talk]]) 12:46, 21 December 2021 (UTC) |
Revision as of 12:46, 21 December 2021
Reduce search range by observation of the results
By taking a look at the results,I tried to search for results by prepending a digit to n.
And there comes the solution:By prepending a digit to n, than n*n must end in n to be a steady square.
So only solutions of one digit before can be solutions.
<lang pascal>
function CalcSquare(n:LongInt;Pot10:byte);
//pot10 is 10^(count of digits of n -1)
//prepend one digit to n
var
dgt: LongInt;
begin
//ex.: n= 5,Pot10 = 1, dgt= 2;-> n2= (2*10*1+5)^2 = 625 For dgt := 1 to 9 do begin // n= 5 , dgt= 2*10 -> n2= 625 n2 = sqr(dgt*10*Pot10+n); n2 = dgt*dgt*100*Pot10*Pot10+2*dgt*10*pot10*n+n*n;
// term: dgt*dgt*100*Pot10*Pot10+2*dgt*10*pot10*n// always has ends in Pot10+1 "0" digits // so n*n must end in n, to be a steady square
end;
</lang>
- Note also that it must end in 1,5 or 6 (not 0 as any number ending in 0 squared ends with twice as many zeros).--Nigel Galloway (talk) 12:46, 21 December 2021 (UTC)