Loading...
Submission
Id When Author Problem Language CPU Memory Verdict
17890 2024-04-24 03:53:40 dnt Sum Game II Java 108 ms 42624 kb Accepted
Test Cases
CPU Memory Verdict
1 99 ms 38552 kb Accepted
2 105 ms 38612 kb Accepted
3 103 ms 38504 kb Accepted
4 108 ms 42236 kb Accepted
5 101 ms 38472 kb Accepted
6 106 ms 42624 kb Accepted
7 105 ms 38960 kb Accepted
Source Code
program.java
Download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6.  
  7. // Read the number of test cases
  8. int t = sc.nextInt();
  9.  
  10. for (int i = 0; i < t; i++) {
  11. // Read the number of friends
  12. long n = sc.nextLong();
  13.  
  14. // Calculate the sum of numbers from 0 to n-1 using the arithmetic series formula
  15. long sum = (n * (n - 1)) / 2;
  16.  
  17. // Output the sum
  18. System.out.println(sum);
  19. }
  20. }
  21. }
  22.