結果
問題 | No.1464 Number Conversion |
ユーザー |
![]() |
提出日時 | 2021-04-02 22:35:26 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 6,424 bytes |
コンパイル時間 | 13,562 ms |
コンパイル使用メモリ | 374,652 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 20:16:04 |
合計ジャッジ時間 | 12,802 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 29 |
ソースコード
#![allow(unused_macros)]#![allow(dead_code)]#![allow(unused_imports)]// # ファイル構成// - use 宣言// - lib モジュール// - main 関数// - basic モジュール//// 常に使うテンプレートライブラリは basic モジュール内にあります。// 問題に応じて使うライブラリ lib モジュール内にコピペしています。// ライブラリのコードはこちら → https://github.com/RheoTommy/at_coder// Twitter はこちら → https://twitter.com/RheoTommyuse std::collections::*;use std::io::{stdout, BufWriter, Write};use crate::basic::*;use crate::lib::*;pub mod lib {/// O(logN)pub fn pow(mut x: i64, mut n: u64) -> i64 {let mut res = 1;while n != 0 {if n & 1 == 1 {res *= x;}n /= 2;x *= x;}res}/// O(logN)pub fn mod_pow(mut x: i64, mut n: u64, m: i64) -> i64 {let mut res = 1;while n != 0 {if n & 1 == 1 {res *= x;}n /= 2;x *= x;res %= m;x %= m;}res % m}/// O(logN)pub fn gcd(mut a: u64, mut b: u64) -> u64 {while b != 0 {let tmp = b;b = a % b;a = tmp;}a}/// O(logN)pub fn lcm(a: u64, b: u64) -> u64 {let g = gcd(a, b);a * b / g}/// O(logN)pub fn ext_gcd(a: i64, b: i64) -> (i64, i64, i64) {if b == 0 {return if a < 0 { (-a, -1, 0) } else { (a, 1, 0) };}let (g, s, t) = ext_gcd(b, a % b);return (g, t, s - (a / b) * t);}pub fn mod_inv(a: i64, m: i64) -> Option<i64> {let (g, xi, _) = ext_gcd(a, -m);if g != 1 {None} else {Some((xi % m + m) % m)}}pub fn mod_div(a: i64, b: i64, n: i64) -> Option<i64> {let d = gcd(gcd(a.abs() as u64, b.abs() as u64), n.abs() as u64) as i64;let inv = mod_inv(a / d, n / d)?;let n = n / d;Some(((inv * b / d) % n + n) % n)}/// O(√NlogN)pub fn divisors(n: u64) -> Vec<u64> {let mut res = Vec::new();for i in 1.. {if i * i > n {break;}if n % i == 0 {res.push(i);if n / i != i {res.push(n / i);}}}res.sort();res}/// O(√N)pub fn is_prime(n: u64) -> bool {for i in 2.. {if i * i > n {break;}if n % i == 0 {return false;}}n > 1 && true}/// O(√N)pub fn factorization(mut n: u64) -> std::collections::HashMap<u64, u64> {let mut res = std::collections::HashMap::new();for i in 2.. {if i * i > n {break;}let mut ex = 0;while n % i == 0 {ex += 1;n /= i;}if ex != 0 {res.insert(i, ex);}}if n != 0 {*res.entry(n).or_insert(0) += 1;}res}pub fn float_to_int(s: &[char], x: u32) -> i64 {if !s.contains(&'.') {return s.iter().collect::<String>().parse::<i64>().unwrap() * 10i64.pow(x);}let n = s.len();let i = s.iter().enumerate().filter(|(_, ci)| **ci == '.').next().unwrap().0;let l = n - i - 1;let t = s.iter().skip_while(|ci| **ci == '0').filter(|ci| **ci != '.').collect::<String>().parse::<i64>().unwrap()* 10i64.pow(x - l as u32);t}}fn main() {let mut sc = Scanner::new();let x = sc.next_string();let x = float_to_int(&x.chars().collect::<Vec<_>>(), 8);let g = gcd(x as u64, 100000000) as i64;println!("{}/{}", x / g, 100000000 / g);}pub mod basic {pub const U_INF: u64 = (1 << 60) + (1 << 30);pub const I_INF: i64 = (1 << 60) + (1 << 30);pub struct Scanner {buf: std::collections::VecDeque<String>,reader: std::io::BufReader<std::io::Stdin>,}impl Scanner {pub fn new() -> Self {Self {buf: std::collections::VecDeque::new(),reader: std::io::BufReader::new(std::io::stdin()),}}fn scan_line(&mut self) {use std::io::BufRead;let mut flag = 0;while self.buf.is_empty() {let mut s = String::new();self.reader.read_line(&mut s).unwrap();let mut iter = s.split_whitespace().peekable();if iter.peek().is_none() {if flag >= 5 {panic!("There is no input!");}flag += 1;continue;}for si in iter {self.buf.push_back(si.to_string());}}}pub fn next<T: std::str::FromStr>(&mut self) -> T {self.scan_line();self.buf.pop_front().unwrap().parse().unwrap_or_else(|_| panic!("Couldn't parse!"))}pub fn next_usize(&mut self) -> usize {self.next()}pub fn next_int(&mut self) -> i64 {self.next()}pub fn next_uint(&mut self) -> u64 {self.next()}pub fn next_chars(&mut self) -> Vec<char> {self.next::<String>().chars().collect()}pub fn next_string(&mut self) -> String {self.next()}pub fn next_char(&mut self) -> char {self.next()}pub fn next_float(&mut self) -> f64 {self.next()}pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {(0..n).map(|_| self.next()).collect::<Vec<_>>()}}}