結果
| 問題 |
No.897 compαctree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-07 23:30:46 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,097 bytes |
| コンパイル時間 | 15,691 ms |
| コンパイル使用メモリ | 377,820 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-23 01:21:29 |
| 合計ジャッジ時間 | 13,897 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
use std::io::Read;
fn solve(t_data: Vec<Vec<u64>>) {
t_data.iter().for_each(|t| {
if t[1] == 1 {
println!("{}", t[0]-1);
} else {
let mut count: u32 = 0;
let mut res = t[0] - 1;
loop {
let nodes: u64 = t[1].pow(count+1);
if res == 0 {
break;
} else if res < nodes {
count += 1;
break;
} else {
res -= nodes;
count += 1;
}
}
println!("{}", count);
}
});
}
fn main() {
let mut all_data = String::new();
std::io::stdin().read_to_string(&mut all_data).ok();
let all_data: Vec<&str> = all_data.trim().split('\n').map(|line| line.trim()).collect();
let q = all_data.iter().next().unwrap().parse().unwrap();
let t_data: Vec<Vec<u64>> = all_data.iter().skip(1).take(q)
.map(|line| line.split_whitespace().map(|w| w.parse::<u64>().unwrap()).collect())
.collect();
solve(t_data);
}