結果
問題 | No.1273 はじめのζ関数 |
ユーザー |
![]() |
提出日時 | 2020-10-31 00:35:18 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 2,250 bytes |
コンパイル時間 | 14,900 ms |
コンパイル使用メモリ | 379,876 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2024-07-22 04:08:39 |
合計ジャッジ時間 | 15,943 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 40 |
ソースコード
use std::io::{self, Write}; use std::{fmt, ops, str}; macro_rules! read { ( $t:ty ) => {{ let mut input = String::new(); io::stdin().read_line(&mut input).unwrap(); input.trim_end().parse::<$t>().ok().unwrap() }}; ( $( $t:ty ),* ) => {{ let mut input = String::new(); io::stdin().read_line(&mut input).unwrap(); let mut iter = input.split_whitespace(); ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* ) }}; } struct IoStr(Vec<char>); impl str::FromStr for IoStr { type Err = (); fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(IoStr(s.chars().collect())) } } impl fmt::Display for IoStr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0.iter().collect::<String>()) } } #[derive(Clone)] struct IoVec<T>(Vec<T>); impl<T: str::FromStr> str::FromStr for IoVec<T> { type Err = T::Err; fn from_str(s: &str) -> Result<Self, Self::Err> { let iter = s.split_whitespace(); Ok(IoVec(iter.map(|x| x.parse()).collect::<Result<_, _>>()?)) } } impl<T: fmt::Display> fmt::Display for IoVec<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0.iter().map(|x| x.to_string()) .collect::<Vec<_>>().join(" ") ) } } impl<T> ops::Index<usize> for IoVec<T> { type Output = T; fn index(&self, i: usize) -> &Self::Output { self.0.get(i - 1).unwrap() } } impl<T> ops::IndexMut<usize> for IoVec<T> { fn index_mut(&mut self, i: usize) -> &mut Self::Output { self.0.get_mut(i - 1).unwrap() } } fn solve(writer: &mut io::BufWriter<io::StdoutLock>) { let x = read!(i32); if x == 2 { writeln!(writer, "{}", 1_000_000).ok(); return; } let mut ans = 0.0; let mut v = vec![1_000_000.0; 500_000]; for i in 1..50 { for j in 2..500_000 { v[j] /= j as f64; if i < x { continue; } ans += v[j]; } } writeln!(writer, "{}", ans.floor() as i64).ok(); } fn main() { let stdout = io::stdout(); let mut writer = io::BufWriter::new(stdout.lock()); solve(&mut writer); }