結果

問題 No.1666 累乗数
ユーザー koba-e964koba-e964
提出日時 2021-09-04 10:56:17
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 2,093 bytes
コンパイル時間 13,075 ms
コンパイル使用メモリ 397,212 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-05-09 23:47:04
合計ジャッジ時間 18,110 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 190 ms
6,816 KB
testcase_02 AC 301 ms
6,940 KB
testcase_03 AC 351 ms
6,944 KB
testcase_04 AC 385 ms
6,940 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

const B: usize = 60;

// #powers <= x
fn calc(x: i64, moe: &[i64]) -> i64 {
    let mut tot = 1;
    for b in 2..60 {
        if moe[b] == 0 {
            continue;
        }
        let mut pass = 1;
        let mut fail = x + 1;
        while fail - pass > 1 {
            let mid = (pass + fail) / 2;
            let mut tmp = mid;
            for _ in 1..b {
                tmp = tmp.saturating_mul(mid);
            }
            if tmp <= x {
                pass = mid;
            } else {
                fail = mid;
            }
        }
        tot += -(pass - 1) * moe[b];
    }
    tot
}

fn main() {
    input! {
        t: usize,
        a: [i64; t],
    }
    let mut moe = vec![0; B];
    moe[1] = 1;
    for i in 1..B {
        for j in 2..(B - 1) / i + 1 {
            moe[i * j] -= moe[i];
        }
    }
    for k in a {
        let mut pass = k * k;
        let mut fail = 0;
        while pass - fail > 1 {
            let mid = (pass + fail) / 2;
            if calc(mid, &moe) >= k {
                pass = mid;
            } else {
                fail = mid;
            }
        }
        println!("{}", pass);
    }
}
0