結果
問題 | No.2074 Product is Square ? |
ユーザー | akakimidori |
提出日時 | 2022-09-16 22:15:30 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 113 ms / 2,000 ms |
コード長 | 2,984 bytes |
コンパイル時間 | 12,924 ms |
コンパイル使用メモリ | 377,972 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-01 13:20:49 |
合計ジャッジ時間 | 15,884 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 65 ms
5,376 KB |
testcase_12 | AC | 69 ms
5,376 KB |
testcase_13 | AC | 113 ms
5,376 KB |
testcase_14 | AC | 76 ms
5,376 KB |
testcase_15 | AC | 65 ms
5,376 KB |
testcase_16 | AC | 69 ms
5,376 KB |
testcase_17 | AC | 113 ms
5,376 KB |
testcase_18 | AC | 77 ms
5,376 KB |
testcase_19 | AC | 64 ms
5,376 KB |
testcase_20 | AC | 69 ms
5,376 KB |
testcase_21 | AC | 113 ms
5,376 KB |
testcase_22 | AC | 76 ms
5,376 KB |
testcase_23 | AC | 64 ms
5,376 KB |
testcase_24 | AC | 69 ms
5,376 KB |
testcase_25 | AC | 113 ms
5,376 KB |
testcase_26 | AC | 76 ms
5,376 KB |
testcase_27 | AC | 64 ms
5,376 KB |
testcase_28 | AC | 69 ms
5,376 KB |
testcase_29 | AC | 113 ms
5,376 KB |
testcase_30 | AC | 76 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
ソースコード
// floor(a ^ (1 / k)) pub fn kth_root(a: u64, k: u64) -> u64 { assert!(k > 0); if a == 0 { return 0; } if k >= 64 { return 1; } if k == 1 { return a; } let valid = |x: u64| -> bool { let mut t = x; for _ in 1..k { let (val, ok) = t.overflowing_mul(x); if !(!ok && val <= a) { return false; } t = val; } true }; let mut ok = 1; let mut ng = 2; while valid(ng) { ok = ng; ng *= 2; } while ng - ok > 1 { let mid = ok + (ng - ok) / 2; if valid(mid) { ok = mid; } else { ng = mid; } } ok } // ---------- begin binary_gcd ---------- pub fn binary_gcd(a: u64, b: u64) -> u64 { if a == 0 || b == 0 { return a + b; } let x = a.trailing_zeros(); let y = b.trailing_zeros(); let mut a = a >> x; let mut b = b >> y; while a != b { let x = (a ^ b).trailing_zeros(); if a < b { std::mem::swap(&mut a, &mut b); } a = (a - b) >> x; } a << x.min(y) } // ---------- end binary_gcd ---------- // ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next<T: FromStr>(&mut self) -> T { self.it.next().unwrap().parse::<T>().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec<u8> { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec<char> { self.it.next().unwrap().chars().collect() } pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) { let t: u32 = sc.next(); for _ in 0..t { let n: usize = sc.next(); let mut a: Vec<u64> = sc.next_vec(n); let mut ans = "Yes"; while let Some(mut v) = a.pop() { for a in a.iter_mut() { let g = binary_gcd(*a, v); *a /= g; v /= g; } let r = kth_root(v, 2); if r * r != v { ans = "No"; } } writeln!(out, "{}", ans).ok(); } }