a = int(input('a='))
b = int(input('b='))
if a > b:
a,b = b,a
t = (b-a) // 2
if a%2 == 0 and b%2 != 0:
t+=1
print(t)
Так как язык не указан, приведу пример на SWI-Prolog.
Код:
read_int(Int) :- read(Int), integer(Int).split_int_by_numbers(0, []) :- !.split_int_by_numbers(N, [Number|Ints]) :- Number is mod(N, 10), RestN is div(N, 10), split_int_by_numbers(RestN, Ints).test_to_div(_, []).test_to_div(N, [Number|Ints]) :- mod(N, Number) =:= 0, test_to_div(N, Ints). test(Int) :- split_int_by_numbers(Int, Numbers), test_to_div(Int, Numbers), write(Int), write(" - Yes!"), nl.test(Int) :- write(Int), write(" - No!"), nl.?- read_int(Int), test(Int).

П0 <-> П1 1 - П1 2 / [x] ИП0 1 - 2 / [x] ИП1 - |x| С/П
Пример: расстояние от дома 1 до дома 5 равно 2.