#!/bin/bash

# Presented as a function to allow all tests to be run ...
function f() {
# ... but the following line may be a standalone program too:
seq 2 $1|factor|sed -r 's/:?( \w+)\1*/-\1*\1/g'|bc|nl -v2|sort -nrk2|sed q
}

for t in 3 10 50 1000 9999; do
	f $t
done