// 階乗? // 普段の構築と違って値が非常に大きいが種類が少ない // 適当に作るとN!をK!(N-K)! にできるがなんか使えるか? // 階乗ってなんか性質あるか // 大雑把にでかいやつ作ってしまうとか? // でかいのひたすら置いてく方針だとどうなるか試す? use std::collections::*; use std::io::Write; type Map = BTreeMap; type Set = BTreeSet; type Deque = VecDeque; fn run() { input!(n: usize); let mut prime = vec![]; enumerate_prime(n, |p| prime.push(p)); prime.reverse(); let calc = |m: usize| -> Vec { assert!(m <= n); let mut res = vec![0; prime.len()]; for (res, p) in res.iter_mut().zip(prime.iter()) { let mut m = m; while m > 0 { *res += m / *p; m /= *p; } } res }; let mut s = calc(n); let mut step = vec![]; while let Some(l) = s.iter().position(|c| *c > 0) { let p = prime[l]; let nu = calc(p); let mut update = false; for i in (1..=(p / 2)).rev() { let a = calc(i); let b = calc(p - i); let v = nu .iter() .zip(a.iter()) .zip(b.iter()) .map(|((nu, a), b)| *nu - *a - *b) .collect::>(); if s.iter().zip(v.iter()).all(|(s, a)| *s >= *a) { step.push((prime[l] - i, i)); for (s, nu) in s.iter_mut().zip(v.iter()) { *s -= *nu; } update = true; break; } } if !update { break; } } let h = step.iter().map(|p| p.0).sum::() + 1; let w = step.iter().map(|p| p.1).sum::() + 1; let mut ans = vec![vec!['#'; w]; h]; let mut pos = (0, 0); ans[pos.0][pos.1] = '.'; for (h, w) in step { for i in 0..=h { for j in 0..=w { ans[pos.0 + i][pos.1 + j] = '.'; } } pos.0 += h; pos.1 += w; } println!("{} {}", h, w); for a in ans { println!("{}", a.iter().collect::()); } } fn main() { run(); } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- // ---------- begin enumerate prime ---------- fn enumerate_prime(n: usize, mut f: F) where F: FnMut(usize), { assert!(1 <= n && n <= 5 * 10usize.pow(8)); let batch = (n as f64).sqrt().ceil() as usize; let mut is_prime = vec![true; batch + 1]; for i in (2..).take_while(|p| p * p <= batch) { if is_prime[i] { let mut j = i * i; while let Some(p) = is_prime.get_mut(j) { *p = false; j += i; } } } let mut prime = vec![]; for (i, p) in is_prime.iter().enumerate().skip(2) { if *p && i <= n { f(i); prime.push(i); } } let mut l = batch + 1; while l <= n { let r = std::cmp::min(l + batch, n + 1); is_prime.clear(); is_prime.resize(r - l, true); for &p in prime.iter() { let mut j = (l + p - 1) / p * p - l; while let Some(is_prime) = is_prime.get_mut(j) { *is_prime = false; j += p; } } for (i, _) in is_prime.iter().enumerate().filter(|p| *p.1) { f(i + l); } l += batch; } } // ---------- end enumerate prime ----------