Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Mar 19, 2019
1 parent 44fcecc commit 94e0e48
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions java/UVA-11254-ConsecutiveIntegers/ConsecutiveSimple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.io.*;
import java.util.*;
import java.lang.Math;

public class ConsecutiveSimple
{
public static void main(String[] args) throws IOException
{
Scanner in = new Scanner(System.in);
while (true)
{
int n = in.nextInt();
if (n == -1)
{
break;
}

for (int l = (int) Math.sqrt(2 * n); l >= 1; l--)
{
int a = (2 * n + l - l * l) / (2 * l);
if ((2 * a + l - 1) * l == 2 * n)
{
System.out.println(String.format("%s = %s + ... + %s", n, a, a + l - 1));
break;
}
}
}
in.close();
System.out.close();
}
}
1 change: 1 addition & 0 deletions myCpps/consecutiveIntegers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ int main()
}
}
}
return 0;
}

0 comments on commit 94e0e48

Please sign in to comment.