You are viewing a single comment's thread. Return to all comments →
Input long para pasar TestCase 1
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(bufferedReader.readLine().trim()); IntStream.range(0, t).forEach(tItr -> { try { int n = Integer.parseInt(bufferedReader.readLine().trim()); long sum= ((long) n *(n+1)) /2; long sumSq=(n*(n+1)*(2L *n+1))/6; long result= (long) ((Math.pow(sum,2)) -sumSq); System.out.println(result); } catch (IOException ex) { throw new RuntimeException(ex); } }); bufferedReader.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #6: Sum square difference
You are viewing a single comment's thread. Return to all comments →
Input long para pasar TestCase 1