-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsecutiveNumbersSum.bk.js
More file actions
54 lines (45 loc) · 1.19 KB
/
ConsecutiveNumbersSum.bk.js
File metadata and controls
54 lines (45 loc) · 1.19 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// https://leetcode-cn.com/problems/consecutive-numbers-sum/
var Test = require('./Common/Test');
var consecutiveNumbersSum = function (n) {
let divisors = [];
let divisorCount = 0;
let candidate = 2;
do {
console.log({ candidate });
if (n % candidate == 0) divisorCount++;
if (n % candidate == 0) divisors.push(candidate);
} while (candidate++ ** 2 < n);
return divisors;
// while(candidate**2<=n){
// }
// for (let i = 0; i < j; i++) {
// const element = array[i];
//
// }
// for
// return findDivisor(n, 2);
function findDivisor(n, candidate) {
switch (true) {
// case Math.sqrt(candidate) > n: return n;
case candidate * candidate > n: return n;
case n % candidate == 0: return candidate;
default: return findDivisor(n, candidate + 1);
}
}
};
function test(n) {
Test.test(consecutiveNumbersSum, n);
}
// test(9);
test(10 ** 9);
function testLongFor(length) {
Test.test(function () {
let val = 0;
for (let i = 0; i < 10 ** length; i++) {
val = i;
}
return val;
});
}
// testLongFor(7);
// test(8)