結果

問題 No.1218 Something Like a Theorem
ユーザー StrorkisStrorkis
提出日時 2020-09-13 15:21:52
言語 Rust
(1.77.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 138,684 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-03 16:24:24
合計ジャッジ時間 3,755 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,508 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let (n, z): (usize, i32) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let pow = |mut a: i32, mut n: usize| -> i32 {
        let mut res = 1;
        while n > 0 {
            if n & 1 > 0 {
                res = res * a;
            }
            a = a * a;
            n >>= 1;
        }
        res
    };

    if z == 1 {
        return println!("No");
    }

    let zn = pow(z, n);
    for x in 1.. {
        let xn = pow(x, n);
        if xn > zn { break; }
        for y in 1.. {
            let yn = pow(y, n);
            if xn + yn == zn {
                return println!("Yes");
            }
            if xn + yn > zn { break; }
        }
    }
    println!("No");
}
0