結果
問題 | No.2709 1975 Powers |
ユーザー |
![]() |
提出日時 | 2024-09-16 16:44:28 |
言語 | Rust (1.83.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,723 bytes |
コンパイル時間 | 15,640 ms |
コンパイル使用メモリ | 378,948 KB |
実行使用メモリ | 73,496 KB |
最終ジャッジ日時 | 2024-09-16 16:44:48 |
合計ジャッジ時間 | 19,457 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | TLE * 1 -- * 24 |
ソースコード
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 apow: Vec<u128> = Vec::new();let mut bpow: Vec<u128> = Vec::new();let mut cpow: Vec<u128> = Vec::new();let mut dpow: Vec<u128> = Vec::new();for i in 1..(arr[n-1]+1) {apow.push(fast_pow_mod(10, i as u128, p));bpow.push(fast_pow_mod(9, i as u128, p));cpow.push(fast_pow_mod(7, i as u128, p));dpow.push(fast_pow_mod(5, i as u128, p));}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];//println!("a: {}, b: {}, c: {}, d: {}",a,b,c,d);let val = (apow[a as usize -1] + bpow[b as usize -1] + cpow[c as usize -1] + dpow[d as usize -1]) % p;if val == q {ans += 1;}}}}}println!("{}", ans);}