結果
問題 | No.1666 累乗数 |
ユーザー | ziita |
提出日時 | 2021-09-03 23:16:02 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 547 ms / 2,000 ms |
コード長 | 4,431 bytes |
コンパイル時間 | 14,123 ms |
コンパイル使用メモリ | 403,920 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-15 17:44:27 |
合計ジャッジ時間 | 22,666 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
6,816 KB |
testcase_01 | AC | 238 ms
6,820 KB |
testcase_02 | AC | 239 ms
6,820 KB |
testcase_03 | AC | 240 ms
6,820 KB |
testcase_04 | AC | 237 ms
6,816 KB |
testcase_05 | AC | 521 ms
6,816 KB |
testcase_06 | AC | 524 ms
6,820 KB |
testcase_07 | AC | 547 ms
6,816 KB |
testcase_08 | AC | 514 ms
6,820 KB |
testcase_09 | AC | 321 ms
6,816 KB |
testcase_10 | AC | 329 ms
6,816 KB |
testcase_11 | AC | 339 ms
6,820 KB |
testcase_12 | AC | 321 ms
6,816 KB |
testcase_13 | AC | 494 ms
6,816 KB |
testcase_14 | AC | 509 ms
6,816 KB |
testcase_15 | AC | 493 ms
6,820 KB |
testcase_16 | AC | 499 ms
6,816 KB |
testcase_17 | AC | 382 ms
6,816 KB |
testcase_18 | AC | 414 ms
6,820 KB |
testcase_19 | AC | 394 ms
6,816 KB |
ソースコード
#![allow(unused_imports)] #![allow(non_snake_case, unused)] // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } use std::io::Write; use std::collections::*; use std::cmp::*; use std::ops::*; use std::marker::*; const INF: i64 = std::i64::MAX/100; const MOD: i64 = 1_000_000_007; // const MOD: i64 = 998244353; struct SieveOfEratosthenes { primes: Vec<usize>, divs: Vec<usize>, mobius: Vec<i64>, } impl SieveOfEratosthenes { pub fn new(n: usize) -> Self { let mut divs = vec![1;n+1]; let mut mobius = vec![-1;n+1]; for i in 2..=n { if divs[i]!=1 { continue; } for j in 1..=n { let val = i*j; if val>n { break; } divs[val as usize] = i; if (val/i)%i==0 { mobius[val as usize] = 0; } else { mobius[val as usize] = -mobius[val as usize]; } } } let mut primes = divs.iter() .enumerate() .filter(|x| *x.1>1 && x.0==*x.1) .map(|x| *x.1) .collect::<Vec<usize>>(); SieveOfEratosthenes { divs, primes, mobius, } } pub fn factors(&self, n: usize) -> Vec<(usize,usize)> { assert!(n+1<=self.divs.len()); let mut ans = vec![]; let mut x = n; while x > 1 { let nxt = self.divs[x]; ans.push(nxt); x /= nxt; } let mut map = HashMap::<usize,usize>::new(); for &a in &ans { *map.entry(a).or_insert(0) += 1; } let mut ret = vec![]; for (&k,&v) in map.iter() { ret.push((k,v)); } ret } } fn main() { input! { t: usize, k: [i64;t], } let p = SieveOfEratosthenes::new(100); for &k in &k { let mut left = 0; let mut right = 10_i64.pow(18)*2; while right-left>1 { let mid = (left+right)/2; let ret = judge(mid,&p.mobius); if ret >= k { right = mid; } else { left = mid; } } println!("{}",right); } } fn judge(x: i64, mobius: &Vec<i64>) -> i64 { let mut ret = 1; for i in 2..=70 { let q = (x as f64).powf(1.0/i as f64) as i64; let mut r = 0; for j in (max(2,q-10)..=q+10).rev() { let mut base = 1; let mut flag = true; for k in 0..i { if base > x/j { flag = false; break; } base *= j; } if flag { r = j; break; } } if r==0 { break; } ret += mobius[i]*(r-1); } ret }