Project Euler #6: Sum square difference

  • + 0 comments
    t = int(input().strip())
    for a0 in range(t):
        n = int(input().strip())
        
        sumofsquare = (n*(n+1)//2)**2 
        squareofsum = n*(n+1)*(2*n+1) // 6 
        print(abs(sumofsquare-squareofsum))