結果

問題 No.2709 1975 Powers
ユーザー well-definedwell-defined
提出日時 2024-09-16 16:26:57
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,329 bytes
コンパイル時間 13,639 ms
コンパイル使用メモリ 378,112 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-09-16 16:27:30
合計ジャッジ時間 18,849 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1,172 ms
5,248 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
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 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

fn fast_pow_mod(base: u128, exp: u128, modulo: u128) -> u128{
    if modulo == 0 {
        return 0;
    }
    if exp == 0 {
        return 1;
    }
    else if exp == 1 {
        return base % modulo;
    }
    else if exp % 2 == 0 {
        return ((fast_pow_mod(base, exp/2, modulo) % modulo) * (fast_pow_mod(base, exp/2, modulo) % modulo)) % modulo;
    }
    else {
        return ((fast_pow_mod(base, (exp-1)/2, modulo) % modulo) * (fast_pow_mod(base, (exp-1)/2, modulo) % modulo) 
            * fast_pow_mod(base, 1, modulo)) % modulo;
    }
}

fn main () {
    input! {
        n: usize,
        p: u128,
        q: u128,
        mut arr: [u128; n],
    }
    arr.sort();
    let mut ans: u64 = 0;
    for i in 0..n {
        let a = arr[i];
        for j in i+1..n {
            let b = arr[j];
            for k in j+1..n {
                let c = arr[k];
                for l in k+1..n {

                    let d = arr[l];
                    let val = (fast_pow_mod(10, a, p)
                        + fast_pow_mod(9, b, p)
                        + fast_pow_mod(7, c, p)
                        + fast_pow_mod(5, d, p)) % p;

                    if val == q {
                        ans += 1;
                    }

                }
            }
        }
    }
    println!("{}", ans);
}
0