Submission #1108439

#TimeUsernameProblemLanguageResultExecution timeMemory
1108439TsaganaOdd-even (IZhO11_oddeven)C++14
0 / 100
1 ms508 KiB
#include<bits/stdc++.h> #define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie(); #define all(x) x.begin(), x.end() #define lnl long long #define pq priority_queue #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define F first #define S second using namespace std; lnl findsquare(lnl s) { if (s == 0 || s == 1) return s; lnl l = 1, r = s / 2, ans; while (l <= r) { lnl M = (l + r) / 2; lnl sqr = M * M; if (sqr == s) return M; if (sqr <= s) { l = M + 1; ans = M; } else r = M - 1; } return ans; } void solve () { lnl n; cin >> n; lnl k = (findsquare((n * 8) + 1) - 1) / 2; lnl s = (n - ((k * (k + 1)) / 2)) * 2; if (!s) {cout << k * k; return ;} k = (k * k) - 1; cout << k + s; } int main() {IOS solve(); return 0;}

Compilation message (stderr)

oddeven.cpp: In function 'long long int findsquare(long long int)':
oddeven.cpp:20:24: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |  lnl l = 1, r = s / 2, ans;
      |                        ^~~
oddeven.cpp: In function 'void solve()':
oddeven.cpp:38:35: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |  lnl k = (findsquare((n * 8) + 1) - 1) / 2;
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...