fork download
  1. /*
  2.   Bismillah Hir Rahmanir Rahim
  3.  
  4.   *MAY ALLAH HELP ME*
  5. */
  6.  
  7. ///Containers Start..
  8. #include <iostream>
  9. #include <cstdio>
  10. #include <cctype>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <ctime>
  14. #include <string>
  15. #include <set>
  16. #include <map>
  17. #include <stack>
  18. #include <queue>
  19. #include <vector>
  20. #include <utility>
  21. #include <math.h>
  22. #include <algorithm>
  23. ///Container End.
  24.  
  25. /// **** So be patient. Indeed, the promise of ALLAH is truth - QURAN - 30:60 ****
  26.  
  27. ///Macro Start..
  28. #define PI acos(-1.0)
  29. #define LL long long
  30. #define pii pair <int, int>
  31. #define ppi pair <pii, int>
  32. #define ff first
  33. #define ss second
  34. #define sz(a) int((a).size())
  35. #define pb push_back
  36. #define mp make_pair
  37. #define nn '\n'
  38. #define all(c) (c).begin(), (c).end()
  39.  
  40. ///Macro End.
  41.  
  42.  
  43. using namespace std;
  44.  
  45.  
  46.  
  47. int main()
  48. {
  49. /// I May Not Be Able To Solve Today's Problems, But I Will Learn, And Obiviously I Can Solve Every Problems One Day :)
  50.  
  51. long long int n, sum, total, x;
  52.  
  53. cin >> n;
  54.  
  55. x = floor( ( sqrt( 8 * n + 1 ) - 1 ) / 2 );
  56.  
  57. //cout << x << endl;
  58.  
  59. total = n - (x * ( x + 1)) / 2;
  60.  
  61. //cout << total << endl;
  62.  
  63. if( total == 0 && x > 0 )
  64. {
  65. cout << x << endl;
  66. }
  67. else if( total == x )
  68. {
  69. cout << x << endl;
  70. }
  71. else if( x > total )
  72. {
  73. cout << total << endl;
  74. }
  75.  
  76.  
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
1039694641