http://projecteuler.net/index.php?section=problems&id=30
この問題は調べる範囲だけ。あとは素直に書くのみ。
#include <iostream> #include "itertools.h" using namespace itertools; const int N = 5; int pow(int n, int e) { return e == 0 ? 1 : n * pow(n, e - 1); } bool is_valid(int n) { return n == sum(map([] (int d) { return pow(d, N); }, digits(n))); } int main() { std::cout << sum(filter(is_valid, range<>(2, (N + 1) * pow(9, N)))) << std::endl; }