結果
| 問題 |
No.2709 1975 Powers
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-04-26 03:08:39 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,393 bytes |
| コンパイル時間 | 23,928 ms |
| コンパイル使用メモリ | 376,996 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-11-08 15:34:33 |
| 合計ジャッジ時間 | 18,255 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 TLE * 1 -- * 23 |
ソースコード
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
}
titia