fork(1) download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4. import java.math.BigInteger;
  5. import java.text.DecimalFormat;
  6. class Tester {
  7. //static long sum=0,sum1=Long.MAX_VALUE;
  8. //DecimalFormat df = new DecimalFormat("#.#####");
  9. static int visited[] = new int[100005];
  10. //Stack s=new Stack();
  11. //static int count=0;
  12. public static final long MOD = (long) (1e9 + 7);
  13. static long h[];
  14. static long j;
  15. // Driver program to test above function
  16. public static void main(String args[])
  17. {
  18. Scanner sc=new Scanner(System.in);
  19. InputReader in = new InputReader(System.in);
  20. OutputStream outputStream = System.out;
  21. PrintWriter out = new PrintWriter(outputStream);
  22. /*....................Code starts Here..............................*/
  23. long n=in.nextLong();
  24. long m=in.nextLong();
  25. if(n<=m)
  26. {
  27. out.println(n);
  28. }
  29. else
  30. {
  31. long ans=0;
  32. long low=m+1;
  33. long high=n;
  34. long ans1=0;
  35. while(low<=high)
  36. {
  37. // out.println(low+" "+high);
  38. long mid=(low+high)/2;
  39. long e=mid-m-1;
  40. double sum=(double)((double)(e)*(double)(e+1))/2;
  41. {
  42. long ini=(long)(n-sum-mid);
  43. if(ini<=0)
  44. {
  45. ans=mid;
  46. high=mid-1;
  47. }
  48. else
  49. {
  50. low=mid+1;
  51. }
  52. }
  53. }
  54. out.println(ans);
  55. }
  56. out.close();
  57. /*.......................Code ends Here................................*/
  58. }
  59.  
  60. static class InputReader {
  61. public BufferedReader reader;
  62. public StringTokenizer tokenizer;
  63.  
  64. public InputReader(InputStream inputstream) {
  65. reader = new BufferedReader(new InputStreamReader(inputstream));
  66. tokenizer = null;
  67. }
  68.  
  69. public String nextLine(){
  70. String fullLine=null;
  71. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  72. try {
  73. fullLine=reader.readLine();
  74. } catch (IOException e) {
  75. throw new RuntimeException(e);
  76. }
  77. return fullLine;
  78. }
  79. return fullLine;
  80. }
  81. public String next() {
  82. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  83. try {
  84. tokenizer = new StringTokenizer(reader.readLine());
  85. } catch (IOException e) {
  86. throw new RuntimeException(e);
  87. }
  88. }
  89. return tokenizer.nextToken();
  90. }
  91. public long nextLong() {
  92. return Long.parseLong(next());
  93. }
  94. public int nextInt() {
  95. return Integer.parseInt(next());
  96. }
  97. public Double nextDouble()
  98. {
  99. return Double.parseDouble(next());
  100. }
  101. }
  102. }
  103.  
Success #stdin #stdout 0.06s 4386816KB
stdin
5 1
stdout
4