summaryrefslogtreecommitdiff
path: root/factor
blob: 81bc61424fdf157622f1a80dfabcfad6429e55e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
factor() {
	n=$1
	f=2

	printf '%d:' $n

	while [ $n -gt $f ]; do
		if [ $((n % f)) -eq 0 ]; then
			printf ' %d' $f
			n=$((n / f))
		else
			f=$((f + 1))
		fi
	done

	if [ $n -gt 1 ]; then
		printf ' %d' $n
	fi

	printf '\n'
}

for i in $*; do
	factor $i
done