
Натуральное число называется автоморфным , если оно равно последним цифрам своего квадрата.
Например, 25^2=625 . Напишите программу, которая находит все автоморфные числа на отрезке [ a , b ] . Входные данные Входная строка содержит два натуральных числа – значения a и b , разделённых пробелами. Гарантируется, что a ≤ b . Выходные данные Программа должна вывести в одну строчку все автоморфные числа на отрезке [ a , b ] , разделив их пробелами. Если таких чисел нет, программа должна вывести число -1. Примеры входные данные 20 100 выходные данные 25 76 На паскале, через циклы, пожалуйста.

Ответы на вопрос

begin
var flag := true;
var a := readinteger;
var b := readinteger;
for var i := a to b do
if (i * i).ToString.EndsWith(i.ToString) then
begin
write(i, ' ');
flag := false;
end;
if flag then write(-1)
end.



To find all automorphic numbers within a given range [a, b], we can iterate through each number in the range and check if it is equal to the last digits of its square. Here's an example program in Pascal that uses loops to solve this problem:
```pascal program AutomorphicNumbers;
function IsAutomorphicNumber(num: Integer): Boolean; var square: Integer; begin square := num * num; while (num > 0) do begin if (num mod 10) <> (square mod 10) then begin IsAutomorphicNumber := False; Exit; end; num := num div 10; square := square div 10; end; IsAutomorphicNumber := True; end;
procedure FindAutomorphicNumbers(a, b: Integer); var i: Integer; found: Boolean; begin found := False; for i := a to b do begin if IsAutomorphicNumber(i) then begin Write(i, ' '); found := True; end; end; if not found then Write(-1); end;
var a, b: Integer; begin Readln(a, b); FindAutomorphicNumbers(a, b); end. ```
This program defines two functions: `IsAutomorphicNumber` and `FindAutomorphicNumbers`. The `IsAutomorphicNumber` function checks if a given number is automorphic by comparing its last digits with the last digits of its square. The `FindAutomorphicNumbers` procedure iterates through the range [a, b] and calls `IsAutomorphicNumber` for each number. If an automorphic number is found, it is printed; otherwise, -1 is printed.
To run this program, you can use an online Pascal compiler or an IDE that supports Pascal. Simply copy the code into the compiler/IDE, compile, and run the program.


Топ вопросов за вчера в категории Информатика









Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili