-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectEuler1.java
More file actions
37 lines (32 loc) · 1.07 KB
/
projectEuler1.java
File metadata and controls
37 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Author: Sreenath T V
* https://www.hackerrank.com/contests/projecteuler/challenges/euler001
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class projectEuler1 {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner kbd = new Scanner(System.in);
int T = kbd.nextInt();
long arr[] = new long[T];
long result[] = new long[T];
for (int i = 0; i < T; i++) {
arr[i] = kbd.nextLong();
}
for (int i = 0; i < T; i++) {
long num = (arr[i] - 1);
long factThree = num / 3;
long factFive = num / 5;
long factFifteen = num / 15;
result[i] = 3 * sumFinder(factThree) + 5 * sumFinder(factFive) - 15 * sumFinder(factFifteen);
System.out.println(result[i]);
}
}
private static long sumFinder(long num) {
return (num * (num + 1)) / 2;
}
}