awk '{for(;i++<$1*$1;)s=s (i%$1)}$0=s'