結果

問題 No.2368 I love a square root of 2
ユーザー 👑 Nachia
提出日時 2023-06-30 21:47:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 2,749 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 83,116 KB
最終ジャッジ日時 2025-02-15 03:44:03
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "..\\Main.cpp"

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#line 2 "D:\\Programming\\VSCode\\competitive-cpp\\nachia\\math\\floor-of-kth-root.hpp"

#include <cassert>

namespace nachia{

namespace internal{

// mod 2^64
constexpr unsigned long long PowerOfULongLong(unsigned long long a, unsigned long long i){
    unsigned long long res = 1;
    while(i){ if(i&1){ res *= a; } i /= 2; a *= a; }
    return res;
}

}

unsigned long long FloorOfKthRoot(unsigned long long real, unsigned long long k){
    using u64 = unsigned long long;
    assert(k != 0);
    if(real <= 1) return real;
    if(k >= 64) return 1;
    if(k == 1) return real;
    struct Precalc{
        // a^i <= x
        static constexpr bool lesseq(u64 a, int i, u64 x) {
            if (a == 0) return true;
            for(int j=0; j<i; j++) x /= a;
            return x >= 1;
        }
        unsigned long long BORDER[64];
        constexpr Precalc() : BORDER() {
            for (int idx = 2; idx <= 63; idx++) {
                u64 l = 0, r = 1ull << 33;
                while (l + 1 < r) {
                    u64 m = (l + r) / 2;
                    if (lesseq(m, idx, ~0ull)) l = m;
                    else r = m;
                }
                BORDER[idx] = r;
            }
        };
    };
    constexpr Precalc precalc;
    u64 l = 0, r = precalc.BORDER[k];
    while (l + 1 < r) {
        u64 m = (l + r) / 2;
        if(internal::PowerOfULongLong(m, k) <= real) l = m;
        else r = m;
    }
    return l;
}

unsigned long long CeilOfKthRoot(unsigned long long real, unsigned long long k){
    if(real <= 1) return real;
    if(k >= 64) return 2;
    if(k == 1) return real;
    unsigned long long x = FloorOfKthRoot(real, k);
    if(internal::PowerOfULongLong(x, k) != real) x++;
    return x;
}

} // namespace nachia
#line 8 "..\\Main.cpp"
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;


int main(){
    i64 N; cin >> N;
    i64 x = 0;
    while(true){
        i64 c = nachia::FloorOfKthRoot(x*x/2, 2) + 1;
        if(c >= N) break;
        N -= c;
        x++;
    }
    vector<pair<i64, i64>> A;
    for(i64 y=0; y*y*2<=x*x; y++) A.emplace_back(y, x - nachia::CeilOfKthRoot(y*y*2, 2));
    sort(A.begin(), A.end(), [](pair<i64, i64> l, pair<i64, i64> r){
        i64 x = r.first - l.first;
        i64 y = r.second - l.second;
        if(x < 0) return x*x*2 < y*y;
        return x*x*2 > y*y;
    });
    cout << A[N-1].second << ' ' << A[N-1].first << endl;
    return 0;
}
0