Trying to convert a number to a string

Well, if you really wanted a constant for the string length required, this old technique would work, I think:

 program testit
use,intrinsic :: iso_fortran_env,  only : int8, int16, int32, int64
! find how many characters to use for integers
integer(kind=int8),parameter  :: b8=ceiling(log10(real(huge(0_int8))))+1
integer(kind=int16),parameter :: b16=ceiling(log10(real(huge(0_int16))))+1
integer(kind=int32),parameter :: b32=ceiling(log10(real(huge(0_int32))))+1
integer(kind=int64),parameter :: b64=ceiling(log10(real(huge(0_int64))))+1
   write(*,'(i0,/,a,1x,i0)')huge(b8),repeat('=',b8),b8
   write(*,'(i0,/,a,1x,i0)')huge(b16),repeat('=',b16),b16
   write(*,'(i0,/,a,1x,i0)')huge(b32),repeat('=',b32),b32
   write(*,'(i0,/,a,1x,i0)')huge(b64),repeat('=',b64),b64
end program testit

But as suggested, just using a character(len=20) variable would work. The formula used here without the +1 would work for finding the string length of the number as well, but not sure that a len_trim() call might be faster, in which case minimizing the string length would probably be faster.

For two digits just going through them all, duplicates, factors, and such aside would be reasonably fast, but you might want to look at the “Greedy Algorithm” as one method of finding it faster

for bigger number of digits, or at least starting with the bigger numbers first and skipping values smaller, as converting to a string is pretty expensive. Some really eye-catching patterns of factors and primes in those palidrome numbers.