Home
Index
Data Structure
Arays
Stacks
Queues
Trees
Hash Table
Advanced
Segment Tree
Algorithms
Searching
Binary Search
Ternary Search
Sorting
Greedy
Graphs
String
DP
Math
Number Theory
Geometry
Combinatorics
Others
Backtracing
Adhoc
Recursion
Ankur's Blog
let's start Code
Home
Online Judge
LightOJ
UVA
Spoj
LeetCode
CodeChef
Hackerrank
Hackerrank
DP
Knapsack
LCS
LIS
Bitmask
Digit
Coin Change
Office
Graph Theory
BFS
DFS
Shortest Path
Topological Sort
Number Theory
Greedy
MST
Fractional Knapsack
Code Repository
STL
Algorithm
Datastructure
Math
Others
Contest problem
Home
»
LeetCode
,
Online Judge
» Consecutive Numbers Sum
Consecutive Numbers Sum
Ankur's Blog
November 17, 2018
No comments
829. Consecutive Numbers Sum
O( sqrt(N) )
Solution:
Code:
class Solution {
public:
int consecutiveNumbersSum(int N)
{
int ans = 0;
for(int n = 2; n*(n+1)/2 <= N; ++n){
if( (N - n*(n+1)/2) %n == 0)ans++;
}
return ans+1;
}
};
Share:
Email This
BlogThis!
Share to X
Share to Facebook
Share to Pinterest
← Newer Post
Older Post →
Home
No comments:
Post a Comment
About Me
Ankur's Blog
View my complete profile
My Social Network
Facebook
About
let's start CODE
Popular
Tags
Blog Archives
Popular Posts
E-maxx training part - 01
Binary Exponentiation 1230 - MODEX Solution 11029 - Leading and Trailing Solution I...
11029 - Leading and Trailing
11029 - Leading and Trailing Topic: Binary Exponentiation
A - Frog 1
A - Frog 1 Solution 01: IH19980412 //copy 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 2...
March 2020
(2)
February 2020
(2)
January 2020
(1)
December 2019
(12)
November 2019
(11)
October 2019
(6)
September 2019
(3)
August 2019
(15)
July 2019
(2)
June 2019
(2)
May 2019
(2)
April 2019
(20)
March 2019
(8)
February 2019
(30)
January 2019
(21)
December 2018
(15)
November 2018
(37)
September 2018
(2)
Labels
Algorithm
(31)
Articulation Points and Bridges
(2)
Atcoder
(3)
BFS
(6)
Binary Search
(2)
Code Repository
(71)
Codechef
(4)
Codeforces
(5)
Contest Problem
(5)
Datastructure
(27)
Devskill
(1)
DFS
(5)
Dijkstra
(2)
Divide and Conquer
(5)
DP
(22)
DSU
(4)
Game Theory
(1)
GeeksForGeeks
(8)
Geometry
(6)
Graph Theory
(20)
Greedy
(8)
HackerEarth
(4)
Hackerrank
(7)
Home
(1)
ICPC
(2)
Kruskal
(1)
LeetCode
(17)
LightOJ
(19)
Math
(5)
MST
(1)
Number Theory
(21)
Online Judge
(84)
PDBS
(2)
Probability
(1)
Resource
(7)
Searching
(1)
Segment Tree
(1)
Sorting
(6)
Spoj
(8)
STL
(9)
String
(11)
Trie Tree
(5)
two pointer
(1)
Upsolve
(3)
USACO
(3)
UVA
(15)
Categories
Algorithm
(31)
Articulation Points and Bridges
(2)
Atcoder
(3)
BFS
(6)
Binary Search
(2)
Code Repository
(71)
Codechef
(4)
Codeforces
(5)
Contest Problem
(5)
Datastructure
(27)
Devskill
(1)
DFS
(5)
Dijkstra
(2)
Divide and Conquer
(5)
DP
(22)
DSU
(4)
Game Theory
(1)
GeeksForGeeks
(8)
Geometry
(6)
Graph Theory
(20)
Greedy
(8)
HackerEarth
(4)
Hackerrank
(7)
Home
(1)
ICPC
(2)
Kruskal
(1)
LeetCode
(17)
LightOJ
(19)
Math
(5)
MST
(1)
Number Theory
(21)
Online Judge
(84)
PDBS
(2)
Probability
(1)
Resource
(7)
Searching
(1)
Segment Tree
(1)
Sorting
(6)
Spoj
(8)
STL
(9)
String
(11)
Trie Tree
(5)
two pointer
(1)
Upsolve
(3)
USACO
(3)
UVA
(15)
►
2020
(5)
►
March
(2)
►
February
(2)
►
January
(1)
►
2019
(132)
►
December
(12)
►
November
(11)
►
October
(6)
►
September
(3)
►
August
(15)
►
July
(2)
►
June
(2)
►
May
(2)
►
April
(20)
►
March
(8)
►
February
(30)
►
January
(21)
▼
2018
(54)
►
December
(15)
▼
November
(37)
Algorithm part - 07
Algorithm part - 06
Algorithm part - 05
Algorithm part-04
Algorithm part- 03
Algorithm part - 02
Algorithm part - 01
Data Structure
Construct the Array
1136 - Division by 3
1182 - Parity
1133 - Array Simulation
773. Sliding Puzzle
771. Jewels and Stones
Minimize Max Distance to Gas Station
779. K-th Symbol in Grammar
SpliBST
1116 - Ekka Dokka
1113 - Discover the Web
1109 - False Ordering
Compare Function for sorting
Count Divisors
778. Swim in Rising Water
786. K-th Smallest Prime Fraction
790. Domino and Tromino Tiling
795. Number of Subarrays with Bounded Maximum
802. Find Eventual Safe States
801. Minimum Swaps To Make Sequences Increasing
Sum of subsets
805. Split Array With Same Average
Bus Routes
Consecutive Numbers Sum
Shortest Bridge
Groups of Special-Equivalent Strings
Minimum Falling Path Sum
Tiling Problem/Defective chessboard problem
Large Number Factorial
►
September
(2)
No comments:
Post a Comment