Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #define PIHAYEM_S_NOGI 1
- #include<bits/stdc++.h>
- using namespace std;
- #ifdef PIHAYEM_S_NOGI
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("no-stack-protector")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
- #pragma GCC optimize("fast-math")
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace __gnu_pbds;
- #define unordered_map gp_hash_table
- #endif
- #define dbg(x) cout << __func__ << ':' << __LINE__ << ' ' << #x << " = " << x << endl
- #define endl '\n'
- #define sqr(x) (x) * (x)
- #define int long long
- #define ll long long
- // #define double long double
- #define eb emplace_back
- #define pb push_back
- #define f first
- #define fr(s) freopen(s, "r", stdin)
- #define fw(s) freopen(s, "w", stdout)
- #define pll pair<long long, long long>
- #define s second
- #define all(x) x.begin(), x.end()
- #define vi vector <int>
- #define pii pair <int, int>
- #define mp(a, b) make_pair(a, b)
- #define forn(i, from, n) for (int i = (int)(from); i < (int)(n); ++i)
- ostream &operator<<(ostream &out, const __int128_t a){
- out << (int)a;
- return out;
- }
- __int128_t sqrtt(__int128_t n){
- __int128_t l = 0, r = n;
- while(r - l > 1){
- // cout << l << ' '
- __int128_t m = (l + r) / 2;
- if(m * m > n) r = m;
- else l = m;
- }
- return l;
- }
- signed main() {
- #ifdef DEBUG
- fr("input.txt");
- // fw("output.txt");
- #else
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int nn;
- cin >> nn;
- __int128_t n = nn;
- __int128_t sq = sqrtt(n);
- if(sq * sq == n){
- if(sq % 2){
- cout << sq << ' ' << sq;
- return 0;
- }
- if((sq / 2) % 2){
- cout << 1 << ' ' << sq;
- return 0;
- } else{
- cout << sq << ' ' << 1;
- return 0;
- }
- }
- // cout << sq << endl;
- __int128_t ssq = sq / 2 * 2 + 1;
- if((sq / 2) % 2 == 0){
- // cout << n << ' ' << sqr(sq / 2 * 2 + 1) << endl;
- if(n >= sqr(sq / 2 * 2 + 1)){
- if(n == sqr(sq / 2 * 2 + 1)){
- cout << ssq << ' ' << ssq << endl;
- return 0;
- }
- if(n - 1 == sqr(sq / 2 * 2 + 1)){
- cout << ssq + 1 << ' ' << ssq << endl;
- return 0;
- }
- if(n - 2 == sqr(sq / 2 * 2 + 1)){
- cout << ssq + 1 << ' ' << ssq + 1 << endl;
- return 0;
- }
- if(n - 3 == sqr(sq / 2 * 2 + 1)){
- cout << ssq << ' ' << ssq + 1 << endl;
- return 0;
- }
- __int128_t k = n - sqr(sq / 2 * 2 + 1);
- if(k % 4 == 0){
- cout << ssq - k / 4 * 2 + 1 << ' ' << ssq + 1 << endl;
- return 0;
- } else if(k % 4 == 1){
- cout << ssq - k / 4 * 2 + 1 << ' ' << ssq << endl;
- return 0;
- } else if(k % 4 == 2){
- cout << ssq - k / 4 * 2 << ' ' << ssq << endl;
- return 0;
- } else cout << ssq - k / 4 * 2 << ' ' << ssq + 1 << endl;
- } else{
- __int128_t k = sqr(sq / 2 * 2 + 1) - n;
- // cout << sqr(sq / 2 * 2 + 1) << ' ' << k << endl;
- if(k % 4 <= 1) cout << ssq;
- else cout << ssq + 1;
- cout << ' ';
- cout << ssq - (k - 1) / 2 - 1 << endl;
- return 0;
- }
- } else{
- if(n - 3 <= sqr(sq / 2 * 2 + 1)){
- // cout << 'x';
- if(n == sqr(sq / 2 * 2 + 1)){
- cout << ssq << ' ' << ssq << endl;
- return 0;
- }
- if(n - 1 == sqr(sq / 2 * 2 + 1)){
- cout << ssq << ' ' << ssq + 1 << endl;
- return 0;
- }
- if(n - 2 == sqr(sq / 2 * 2 + 1)){
- cout << ssq + 1 << ' ' << ssq + 1 << endl;
- return 0;
- }
- if(n - 3 == sqr(sq / 2 * 2 + 1)){
- cout << ssq + 1 << ' ' << ssq << endl;
- return 0;
- }
- __int128_t k = sqr(sq / 2 * 2 + 1) - n - 1 + 4;
- // cout << k << endl;
- if(k % 4 == 0){
- cout << ssq - k / 4 * 2 + 1 << ' ' << ssq << endl;
- return 0;
- } else if(k % 4 == 1){
- cout << ssq - k / 4 * 2 + 1 << ' ' << ssq + 1 << endl;
- return 0;
- } else if(k % 4 == 2){
- cout << ssq - k / 4 * 2 << ' ' << ssq + 1 << endl;
- return 0;
- } else cout << ssq - k / 4 * 2 << ' ' << ssq << endl;
- } else{
- __int128_t k = n - sqr(sq / 2 * 2 + 1);
- // cout << k << ' ' << ssq << endl;
- if(k % 4 == 0 || k % 4 == 3) cout << ssq + 1;
- else cout << ssq;
- cout << ' ';
- cout << ssq - (k - 4) / 2 - 1 << endl;
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement