結果
問題 | No.1273 はじめのζ関数 |
ユーザー |
![]() |
提出日時 | 2020-10-30 22:26:07 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,171 bytes |
コンパイル時間 | 16,090 ms |
コンパイル使用メモリ | 382,140 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-22 01:40:24 |
合計ジャッジ時間 | 29,123 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 39 WA * 1 |
ソースコード
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 zeta(n: i32) -> f64 {let mut res = 0.0;for i in 2..5_000 {res += (1.0 / i as f64).powi(n);}res}fn solve(writer: &mut io::BufWriter<io::StdoutLock>) {let x = read!(i32);let mut ans = 0.0;for i in x..5_000 {ans += zeta(i);}ans *= 1_000_000.0;writeln!(writer, "{}", ans.floor() as i64).ok();}fn main() {let stdout = io::stdout();let mut writer = io::BufWriter::new(stdout.lock());solve(&mut writer);}