結果

問題 No.1143 面積Nの三角形
ユーザー koba-e964koba-e964
提出日時 2021-09-18 12:24:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 93 ms / 800 ms
コード長 1,964 bytes
コンパイル時間 3,033 ms
コンパイル使用メモリ 141,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 22:14:03
合計ジャッジ時間 5,143 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 42 ms
4,380 KB
testcase_12 AC 52 ms
4,376 KB
testcase_13 AC 55 ms
4,380 KB
testcase_14 AC 12 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 91 ms
4,376 KB
testcase_17 AC 93 ms
4,380 KB
testcase_18 AC 80 ms
4,376 KB
testcase_19 AC 76 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn nth(a: i64, n: i64) -> i64 {
    let mut pass = 0;
    let mut fail = std::cmp::min(a, 1 << ((60 + n - 1) / n)) + 1;
    while fail - pass > 1 {
        let mid = (fail + pass) / 2;
        let mut tmp = 1i64;
        for _ in 0..n {
            tmp = tmp.saturating_mul(mid);
        }
        if tmp <= a {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    pass
}

fn main() {
    let n: i64 = get();
    let mut div = vec![];
    for s in 1..n + 1 {
        if n * n % s == 0 {
            div.push(s);
            if s != n {
                div.push(n * n / s);
            }
        }
    }
    div.sort();
    let m = div.len();
    let mut ans = 0;
    for i in 0..m {
        let s = div[i];
        if s >= 2 * n { continue; }
        for j in i..m {
            if div[j] % s != 0 {
                continue;
            }
            let sa = div[j] / s;
            if sa >= s { continue; }
            let a = s - sa;
            let t = 2 * s - a; // b + c
            let bc = n * n / div[j] + t * s - s * s; // b * c
            let d = t * t - 4 * bc;
            let d2 = nth(d, 2);
            if d2 * d2 != d { continue; }
            let b = (t - d2) / 2;
            if a > b { continue; }
            ans += 1;
        }
    }
    println!("{}", ans);
}
0