Skip to content

Commit 94e0e48

Browse files
committed
1 parent 44fcecc commit 94e0e48

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.lang.Math;
4+
5+
public class ConsecutiveSimple
6+
{
7+
public static void main(String[] args) throws IOException
8+
{
9+
Scanner in = new Scanner(System.in);
10+
while (true)
11+
{
12+
int n = in.nextInt();
13+
if (n == -1)
14+
{
15+
break;
16+
}
17+
18+
for (int l = (int) Math.sqrt(2 * n); l >= 1; l--)
19+
{
20+
int a = (2 * n + l - l * l) / (2 * l);
21+
if ((2 * a + l - 1) * l == 2 * n)
22+
{
23+
System.out.println(String.format("%s = %s + ... + %s", n, a, a + l - 1));
24+
break;
25+
}
26+
}
27+
}
28+
in.close();
29+
System.out.close();
30+
}
31+
}

myCpps/consecutiveIntegers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ int main()
3636
}
3737
}
3838
}
39+
return 0;
3940
}

0 commit comments

Comments
 (0)