-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.h
36 lines (33 loc) · 798 Bytes
/
solution.h
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
/*
Code generated by https://github.com/goodstudyqaq/leetcode-local-tester
*/
#if __has_include("../utils/cpp/help.hpp")
#include "../utils/cpp/help.hpp"
#elif __has_include("../../utils/cpp/help.hpp")
#include "../../utils/cpp/help.hpp"
#else
#define debug(...) 42
#endif
vector<int> V = {0, 1};
void init() {
if (V.size() > 2) return;
for (int i = 2;; i++) {
long long val = 1LL * (i + 1) * i / 2;
if (val > 1e9) break;
V.push_back(val);
}
}
class Solution {
public:
int consecutiveNumbersSum(int n) {
init();
debug(V.size());
int ans = 0;
for (int i = 1; i < V.size(); i++) {
int val = V[i];
if (val > n) break;
if ((n - val) % i == 0) ans++;
}
return ans;
}
};