当前位置:网站首页>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;
}
};
边栏推荐
- Go tool cli for command line implementation
- LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
- Hal library setting STM32 interrupt
- 家居网购项目
- Thread data sharing and security -threadlocal
- FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)
- Feign remote call and getaway gateway
- C#实现基于广度优先BFS求解无权图最短路径----完整程序展示
- 数据交换 JSON
- split(),splice(),slice()傻傻分不清楚?
猜你喜欢

Feature pyramid networks for object detection

EDLines: A real-time line segment detector with a false detection control翻译

二叉树神级遍历:Morris遍历

几行事务代码,让我赔了16万

终极套娃 2.0 | 云原生交付的封装

Introduction to EtherCAT

How to verify whether the contents of two files are the same

Gorilla/mux framework (RK boot): RPC error code design

The value of the second servo encoder is linked to the NC virtual axis of Beifu PLC for display

IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
随机推荐
Pyramid Scene Parsing Network【PSPNet】论文阅读
MySQL knowledge points
Latest interface automation interview questions
手把手带你了解一块电路板,从设计到制作(干货)
C language EXECL function
Feign remote call and getaway gateway
BluePrism注册下载并安装-RPA第一章
A few lines of transaction codes cost me 160000 yuan
Introduction to the core functions of webrtc -- an article to understand peerconnectionfactoryinterface rtcconfiguration peerconnectioninterface
串口接收数据方案设计
Nacos
pytorch训练深度学习网络设置cuda指定的GPU可见
Pytest -- plug-in writing
Valid brackets (force deduction 20)
Elk elegant management server log
Research on target recognition and tracking based on 3D laser point cloud
Overview of EtherCAT principle
CX5120控制汇川IS620N伺服报错E15解决方案
服务器渲染技术jsp
详解Spark运行模式(local+standalone+yarn)