思路:
数论。参考了https://leetcode.cn/problems/consecutive-numbers-sum/solution/by-ac_oier-220q/。
实现:
1 class Solution { 2 public: 3 int consecutiveNumbersSum(int n) { 4 int res=0; 5 for(int i=1;i*i<2*n;i++){ 6 if(2*n%i==0){ 7 int j=2*n/i-i+1; 8 if(j%2==0 and j>=2){ 9 res++; 10 } 11 } 12 } 13 return res; 14 } 15 };