Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- Ways=1
- [[ "${1}" == -[1-9] ]] && { Ways=$(( 0 - ${1} )); shift; }
- Max="${1:-100000}"
- Root=0
- for (( Root = 1; (Root * Root * Root) <= Max; ++Root )); do : ; done
- Root=$(( Root - 1 ))
- printf 'Ways is %d; Max is %d; Root is %d\n' "${Ways}" "${Max}" "${Root}"
- for (( a = 1; a <= Root; ++a )); do
- for (( b = a; b <= Root; ++b )); do
- v=$(( a * a * a + b * b * b ))
- (( v <= Max )) &&
- printf -v N[v] '%s %d,%d' "${N[${v}]}" "${a}" "${b}"
- done
- done
- r="${#N[@]}"
- (( Ways > 1 )) && for n in ${!N[@]}; do
- read -a Fact <<<"${N[${n}]}"
- (( ${#Fact[@]} < Ways )) && unset N[${n}]
- done
- printf 'Showing %d %d-way of %d results.\n' "${#N[@]}" "${Ways}" "${r}"
- for n in ${!N[@]}; do
- printf '%8d %s\n' "${n}" "${N[${n}]}"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement