define gcd (i, j) { while(j != 0) { k = j j = i % j i = k } return i } define is_perfect_totient (num) { tot = 0 for (i = 1; i < num; i++) { if (gcd(num, i) == 1) { tot += 1 } } sum = tot + cache[tot] cache[num] = sum return num == sum } j = 1 count = 0 # we only go to 15 (not 20) because bc is very slow while (count <= 15) { if (is_perfect_totient(j)) { print j, " " count += 1 } j += 1 } print "\n" quit