$n=<>; $l=ab; while($n){ $r=2+sqrt($n)|0; while($r*($r+1)>$n){ --$r; } print$l x$r; $n-=$r*($r+1); if($n>=$r+1){ print substr $l,0,1; $n-=$r+1; } $l=~y/a-z/c-zab/; }