Tuesday, April 14, 2015

HackerRank::Contests::ProjectEuler::Project Euler #6: Sum square difference

      Pre-calculation can still help. We can calculate the square of the sums in one go, it will be (N*(N+1)/2)^2. And we can build an array named SUM where SUM[i] will be the sum of squares of all numbers from 1 to i. When we are done building this, processing the input takes only a few lines.

 


No comments:

Post a Comment