Skip to content

Instantly share code, notes, and snippets.

@kou029w
Last active October 5, 2017 11:51
Show Gist options
  • Save kou029w/867ba438c024f5bc7f6de6f3bff1d1c1 to your computer and use it in GitHub Desktop.
Save kou029w/867ba438c024f5bc7f6de6f3bff1d1c1 to your computer and use it in GitHub Desktop.
factor.sh
#!/bin/bash
# i=$1 p=${2:-2}
# while (( i != 1 )); do
# if (( i % p )); then
# (( p++ ))
# else
# echo $p
# (( i /= p, p = 2 ))
# fi
# done
# i=$1 p=${2:-2};while((i!=1));do if((i%p));then((p++));else echo $p;((i/=p,p=2));fi;done
# for (( i=$1, p=${2:-2}; i != 1; p++ )); do
# (( i % p == 0 )) && {
# echo $p
# (( i /= p, p = 1 ))
# }
# done
for((i=$1,p=${2:-2};i!=1;p++));do((i%p==0))&&echo $p&&((i/=p,p=1));done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment