結果

問題 No.2709 1975 Powers
ユーザー titiatitia
提出日時 2024-04-26 03:08:39
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,393 bytes
コンパイル時間 1,519 ms
コンパイル使用メモリ 168,264 KB
実行使用メモリ 8,992 KB
最終ジャッジ日時 2024-04-26 03:08:45
合計ジャッジ時間 5,326 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,168 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 409 ms
5,376 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 std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut stdin_lock = stdin.lock();

    let mut line = String::new();
    stdin_lock.read_line(&mut line).unwrap();
    let mut n_p_q = line.trim().split_whitespace().map(|x| x.parse::<usize>().unwrap());
    let n = n_p_q.next().unwrap();
    let p = n_p_q.next().unwrap();
    let q = n_p_q.next().unwrap();

    line.clear();
    stdin_lock.read_line(&mut line).unwrap();
    let mut a: Vec<usize> = line.trim().split_whitespace().map(|x| x.parse::<usize>().unwrap()).collect();
    a.sort();

    let mut ans = 0;
    for i in 0..n {
        for j in i + 1..n {
            for k in j + 1..n {
                for l in k + 1..n {
                    let a_i = a[i];
                    let b = a[j];
                    let c = a[k];
                    let d = a[l];

                    if (mod_pow(10, a_i, p) + mod_pow(9, b, p) + mod_pow(7, c, p) + mod_pow(5, d, p)) % p == q {
                        ans += 1;
                    }
                }
            }
        }
    }

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

fn mod_pow(mut base: usize, mut exp: usize, modulus: usize) -> usize {
    let mut result = 1;
    base %= modulus;
    while exp > 0 {
        if exp % 2 == 1 {
            result = (result * base) % modulus;
        }
        exp >>= 1;
        base = (base * base) % modulus;
    }
    result
}
0