Skip to content

Instantly share code, notes, and snippets.

@johirbuet
Created February 26, 2018 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johirbuet/a70711c54c67e9cb135f27386cd0d18f to your computer and use it in GitHub Desktop.
Save johirbuet/a70711c54c67e9cb135f27386cd0d18f to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class UVA12149 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()) {
int n = sc.nextInt();
if(n == 0) {
break;
}
int total = n*(n+1)*(2*n+1)/6;
System.out.println(total);
}
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment