abc190_d - Staircase Sequences

Editorial

Time complexity: $O(\sqrt{n})$

Memory complexity: $O(1)$

Click to show code.


using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(void)
{
    ios::sync_with_stdio(false), cin.tie(NULL);
    ll n;
    cin >> n;
    n *= 2;
    int ans = 0;
    for (ll k = 1, sqn = sqrt(n); k <= sqn; ++k)
        if (n % k == 0 and (n / k - k + 1) % 2 == 0)
            ans += 2;
    cout << ans << endl;
    return 0;
}