leetcode829 连续整数求和
作者:互联网
思路:
数论。参考了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 };
标签:ac,cn,leetcode829,求和,res,oier,整数,int,numbers 来源: https://www.cnblogs.com/wangyiming/p/16351811.html