File tree 3 files changed +57
-0
lines changed
3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ object MultiplesOf3Or5 {
2
+ def solution (number : Long ): Long =
3
+ (3L until number).filter(i => i % 3L == 0L || i % 5L == 0L ).sum
4
+ }
Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+
3
+ public int solution (int number ) {
4
+ int result = 0 ;
5
+ if (number > 3 )
6
+ {
7
+ int min = 3 ;
8
+ int count = (number - 1 ) / 3 ;
9
+ int max = number - 1 ;
10
+ while (max % 3 != 0 )
11
+ {
12
+ max --;
13
+ }
14
+ int tempResult = count * (min + max ) / 2 ;
15
+ result += tempResult ;
16
+ }
17
+ if (number > 5 )
18
+ {
19
+ int min = 5 ;
20
+ int count = (number - 1 ) / 5 ;
21
+ int max = number - 1 ;
22
+ while (max % 5 != 0 )
23
+ {
24
+ max --;
25
+ }
26
+ int tempResult = count * (min + max ) / 2 ;
27
+ result += tempResult ;
28
+ }
29
+ if (number > 15 )
30
+ {
31
+ int min = 15 ;
32
+ int count = (number - 1 ) / 15 ;
33
+ int max = number - 1 ;
34
+ while (max % 15 != 0 )
35
+ {
36
+ max --;
37
+ }
38
+ int tempResult = count * (min + max ) / 2 ;
39
+ result -= tempResult ;
40
+ }
41
+
42
+ return result ;
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ function solution ( number ) {
2
+ let result = 0 ;
3
+ for ( let i = 3 ; i < number ; i ++ ) {
4
+ if ( i % 3 === 0 || i % 5 === 0 ) {
5
+ result += i ;
6
+ }
7
+ }
8
+ return result ;
9
+ }
You can’t perform that action at this time.
0 commit comments