当前位置:网站首页>Leetcode:829. Sum of continuous integers
Leetcode:829. Sum of continuous integers
2022-07-01 03:32:00 【Re:fused】
subject :829. Sum consecutive integers
The question :
Given a positive integer n, return Continuous positive integers satisfy that the sum of all numbers is n Number of groups .
Answer key :
I thought of the equal deviation as 1 Equal difference sequence of , So there's a formula m a 1 + ( m − 1 ) m / 2 = m ( m a 1 + ( m − 1 ) / 2 ) = n ma_1+(m-1)m/2=m(ma_1+(m-1)/2) = n ma1+(m−1)m/2=m(ma1+(m−1)/2)=n, It can be seen that m Must be n My silver , also m-1 Even number , To ensure a 1 a_1 a1 Integers .
Code :
class Solution {
public:
int consecutiveNumbersSum(int n) {
int half = sqrt(n);
int cn = 0;
for(int i = 1; i <= half; i++){
if(i == half && i*i == n){
if((i-1)%2 == 0)cn++;
}
else{
if(n % i == 0){
if((i -1)%2 == 0)cn++;
int other = n / i;
if((other-1)%2 == 0)cn++;
}
}
}
return cn;
}
};
边栏推荐
- Introduction and installation of Solr
- So easy deploy program to server
- Home online shopping project
- Hal library setting STM32 interrupt
- Pyramid Scene Parsing Network【PSPNet】论文阅读
- Ultimate dolls 2.0 | encapsulation of cloud native delivery
- E15 solution for cx5120 controlling Huichuan is620n servo error
- LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
- Golang multi graph generation gif
- gcc使用、Makefile总结
猜你喜欢

Detailed list of errors related to twincat3 ads of Beifu

家居网购项目

Analyze datahub, a new generation metadata platform of 4.7K star
![[nine day training] content III of the problem solution of leetcode question brushing Report](/img/7e/1e76181e56ef7feb083f9662df71c7.jpg)
[nine day training] content III of the problem solution of leetcode question brushing Report

还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板

So easy deploy program to server

A few lines of transaction codes cost me 160000 yuan

How do spark tasks of 10W workers run? (Distributed Computing)
![[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理

雪崩问题以及sentinel的使用
随机推荐
torch.histc
ctfshow爆破wp
Home online shopping project
Introduction to ieda right click source file menu
Druid监控统计数据源
Golang多图生成gif
pytorch训练深度学习网络设置cuda指定的GPU可见
数据库DDL(Data Definition Language,数据定义语言)知识点
Finally in promise
Edge drawing: a combined real-time edge and segment detector
C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
家居网购项目
Common interview questions for performance test
EDLines: A real-time line segment detector with a false detection control翻译
Listener listener
Learning notes for introduction to C language multithreaded programming
Elk elegant management server log
Valid brackets (force deduction 20)
LeetCode 128最长连续序列(哈希set)
串口接收数据方案设计