A relatively simple math problem.
The question asks us how many consecutive positive integers a positive integer \ (n \) can be split. Then these consecutive positive integers will form an arithmetic sequence with tolerance \ (1 \) .
If the first item of the sequence is \ (a \) and the last item is \ (b \) , then the sum of the difference sequence is \ (\ dfrac {(a + b) (b-a + 1)} {2} \) .
Then come to push a wave of persimmons:
Therefore, we only need to enumerate \ ((a + b) \) to determine whether it is a factor of \ (2n \) . If yes, find \ ((b-a + 1) \) . If the parity of \ ((a + b) \) and \ ((b-a + 1) \) are different, the number of schemes increases.
The time complexity is \ (O (\ sqrt {n}) \) and the constant is \ (\ sqrt {2} \) .
\ (11 \) line code (unpressed line):
#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
scanf("%lld",&n);
n<<=1; // 之后不需要使用 n 了,只需要用 2n,故直接将 n 乘上 2
int ans=0,m=sqrt(n);
for (register int i=1,j;i<=m;i++) ans+=!(n%i)&&(i&1)^(n/i&1); // 位运算。等价于 if (n%i==0&&i%2!=n/i%2) ans++;
printf("%d",ans);
return 0;
}