Is this what you are looking for? import std.stdio; import std.range : iota; import std.algorithm : map, filter, joiner; import std.typecons : tuple; import std.math : sqrt, floor;
void main(){ immutable limit = cast(size_t)floor(sqrt(1_000.0)); auto r = iota(2,limit).map!(m=>iota(1,m-1).map!(n=>tuple(m,n))).joiner .filter!(t=>2*t[0]*(t[0]+t[1])==1_000) .map!(t=>(t[0]^^4-t[1]^^4)*(2*t[0]*t[1])); writeln(r.front); }