Kaprekar
repunits and Kaprekar numbers
Let k be an n-digit positive integer. Square it and add the right n digits to the left n or n-1 digits. If the sum is k, then k is call a Kaprekar number. For example, 297 is a Kaprekar number because 2972=88209, 88+209=297.
Kaprekar numbers have relation to repunits. An n-digit positive integer X is a Kaprekar number if and only if X2-X is a multiple of 9Rn = 10n-1.
a program for computing Kaprekar numbers
This is a pari/gp program for computing Kaprekar numbers.
{
for(d=1,59,
f=factor(10^d-1);
k=matsize(f)[1];
l=[];
for(i=0,2^k-1,
x=lift(chinese(vector(k,j,Mod(bittest(i,j-1),f[j,1]^f[j,2]))));
if(x==0,x=10^d-1);
if(x>=10^(d-1),l=concat(l,[x]))
);
l=vecsort(l);
for(i=1,#l,print(l[i]))
)
}