Skip to content

Commit 2a47965

Browse files
committed
Solve 038, 044 in typical90
1 parent 99e0340 commit 2a47965

File tree

5 files changed

+128
-8
lines changed

5 files changed

+128
-8
lines changed

atcoder/rust/typical90/src/bin/018.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
use std::cmp::*;
44
use std::collections::*;
5+
use std::f64::consts::PI;
56
use std::io::Write;
67
use std::ops::Bound::*;
78

8-
use itertools::*;
99
use itertools::__std_iter::once;
10+
use itertools::*;
1011
use itertools_num::ItertoolsNum;
11-
use proconio::*;
12+
use libm::{atan2, cos, sin};
1213
use proconio::marker::*;
14+
use proconio::*;
1315
use superslice::*;
1416

1517
#[macro_export]
@@ -21,8 +23,34 @@ macro_rules! min {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr
2123
#[macro_export]
2224
macro_rules! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }
2325

24-
fn main() {
26+
fn main() {
2527
input! {
26-
28+
t: f64,
29+
l: f64, x: f64, y: f64,
30+
q: usize,
31+
e: [f64; q],
32+
}
33+
34+
// t/4 == 0, -L/2, L/2)
35+
// t/2 == 0, 0, L)
36+
// 3t/4 == 0, L/2, L/2)
37+
// t/2 = 半周
38+
// t/4 = 4分の1週
39+
// t / t = t分の1周
40+
41+
// (x-a)^2+(y-b)^2=r^2
42+
// (y-b)^2=r^2-(x-a)^2
43+
// y^2 - 2yb + b^2=r^2-(x-a)^2
44+
45+
let radius = l / 2.0;
46+
for i in e {
47+
let cur_i = i % t;
48+
let cur_angle = 360.0 / t * cur_i;
49+
let cur_y = radius * cos(cur_angle * (PI / 180.0));
50+
let cur_z = radius * sin(cur_angle * (PI / 180.0));
51+
println!(
52+
"{}",
53+
atan2(cur_z, (x.powf(2.0) + (cur_y - y).powf(2.0)).sqrt()) / PI * 180.0
54+
)
2755
}
2856
}

atcoder/rust/typical90/src/bin/032.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ use itertools_num::ItertoolsNum;
1111
use proconio::*;
1212
use proconio::marker::*;
1313
use superslice::*;
14+
use num_integer::lcm;
1415

1516
fn main() {
1617
input! {
17-
18+
a: usize, b: usize,
1819
}
20+
21+
println!(lcm(a, b));
1922
}

atcoder/rust/typical90/src/bin/038.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ use itertools_num::ItertoolsNum;
1111
use proconio::*;
1212
use proconio::marker::*;
1313
use superslice::*;
14+
use num_integer::lcm;
1415

1516
fn main() {
1617
input! {
17-
18+
a: u128, b: u128,
1819
}
20+
21+
let ans = lcm(a, b);
22+
if ans <= 10_u128.pow(18_u32) {
23+
println!("{}", ans)
24+
} else {
25+
println!("{}", "Large")
26+
};
1927
}

atcoder/rust/typical90/src/bin/044.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ use superslice::*;
1414

1515
fn main() {
1616
input! {
17+
n: usize, q: usize,
18+
mut a: [usize; n],
19+
txy: [(usize, usize, usize); q],
20+
}
1721

22+
let mut shift_count = 0;
23+
for (t, x, y) in txy {
24+
match t {
25+
1 => {
26+
let x_i = if x <= shift_count { n + x - shift_count } else { x - shift_count } - 1;
27+
let y_i = if y <= shift_count { n + y - shift_count } else { y - shift_count } - 1;
28+
let tmp = a[x_i];
29+
a[x_i] = a[y_i];
30+
a[y_i] = tmp;
31+
}
32+
2 => {
33+
shift_count += 1;
34+
shift_count %= n;
35+
}
36+
3 => {
37+
let x_i = if x <= shift_count { n + x - shift_count } else { x - shift_count } - 1;
38+
println!("{}", a[x_i])
39+
}
40+
_ => {}
41+
}
1842
}
1943
}

atcoder/rust/typical90/src/bin/085.rs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,72 @@ use std::collections::*;
55
use std::io::Write;
66
use std::ops::Bound::*;
77

8-
use itertools::*;
98
use itertools::__std_iter::once;
9+
use itertools::*;
1010
use itertools_num::ItertoolsNum;
11-
use proconio::*;
1211
use proconio::marker::*;
12+
use proconio::*;
1313
use superslice::*;
1414

1515
fn main() {
1616
input! {
17+
k: usize
18+
}
19+
20+
let primes = prime_factors(k);
21+
println!("{:?}", primes)
22+
}
23+
24+
fn prime_factors(mut n: usize) -> HashMap<usize, usize> {
25+
let mut primes = sieve_of_eratosthenes(f64::sqrt(n as f64) as usize);
26+
let mut hm_primes = HashMap::new();
27+
28+
for prime in primes {
29+
while n % prime == 0 {
30+
n /= prime;
31+
if hm_primes.contains_key(&prime) {
32+
let mut x = hm_primes.get_mut(&prime).unwrap();
33+
*x += 1;
34+
} else {
35+
hm_primes.insert(prime, 1);
36+
}
37+
}
38+
}
39+
40+
if n > 1 {
41+
if hm_primes.contains_key(&n) {
42+
let mut x = hm_primes.get_mut(&n).unwrap();
43+
*x += 1;
44+
} else {
45+
hm_primes.insert(n, 1);
46+
}
47+
}
48+
hm_primes
49+
}
50+
51+
fn sieve_of_eratosthenes(n: usize) -> Vec<usize> {
52+
let mut spf = vec![None; n + 1];
53+
let mut is_prime = vec![true; n + 1];
54+
let mut primes = Vec::new();
55+
56+
is_prime[0] = false;
57+
is_prime[1] = false;
58+
59+
for i in 2..n + 1 {
60+
if is_prime[i] {
61+
primes.push(i);
62+
spf[i] = Some(i);
63+
}
64+
65+
for prime in &primes {
66+
if i * prime >= n + 1 || prime > &spf[i].unwrap() {
67+
break;
68+
}
69+
70+
is_prime[i * prime] = false;
1771

72+
spf[i * prime] = Some(*prime);
73+
}
1874
}
75+
primes
1976
}

0 commit comments

Comments
 (0)