Skip to content

Commit

Permalink
Add atcoder/abc336/b.rs atcoder/abc336/c.rs atcoder/abc336/e.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
koba-e964 committed May 6, 2024
1 parent e7780f9 commit b7fcc33
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 3 deletions.
34 changes: 34 additions & 0 deletions atcoder/abc336/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
let mut n: i64 = get();
let mut x = 0;
while n % 2 == 0 {
n /= 2;
x += 1;
}
println!("{x}");
}
37 changes: 37 additions & 0 deletions atcoder/abc336/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
let mut n: i64 = get();
let mut c = 1;
let mut s = 0;
n -= 1;
while n > 0 {
s += (n % 5) * c * 2;
c *= 10;
n /= 5;
}
println!("{s}");
}
65 changes: 65 additions & 0 deletions atcoder/abc336/e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn f(n: [usize; 15], d: usize) -> i64 {
let mut dp = vec![vec![[0i64; 2]; d]; d + 1];
dp[0][0][1] = 1;
for i in 0..15 {
let mut ep = vec![vec![[0i64; 2]; d]; d + 1];
for j in 0..d + 1 {
for k in 0..d {
for eq in 0..2 {
let val = dp[j][k][eq];
for q in 0..10 {
if eq == 1 && q > n[i] {
break;
}
let neq = if eq == 1 && q == n[i] { 1 } else { 0 };
if j + q > d {
continue;
}
ep[j + q][(10 * k + q) % d][neq] += val;
}
}
}
}
dp = ep;
}
dp[d][0][0] + dp[d][0][1]
}

fn main() {
let mut n: i64 = get();
let mut dig = [0; 15];
for i in 0..15 {
dig[14 - i] = (n % 10) as usize;
n /= 10;
}
let mut ans = 0;
for d in 1..127 {
ans += f(dig, d);
}
println!("{ans}");
}
3 changes: 0 additions & 3 deletions atcoder/abc336/remain.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
b
c
d
e
f
g

0 comments on commit b7fcc33

Please sign in to comment.