Project Euler #87: Prime power triples

  • + 0 comments

    Since you have precalculated all triplets, why not also precompute for all the test cases? Create a cummulative array c with c[i] having number of triplets less than or equal to i then just print c[a[tt]] for each case which would be a O(t) operation (just for counting triplets, excluding generation of all triplets) compared to O(t^2) for counting from begining for each test case.