Problem:
Score : 200 points

Problem Statement

Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times:

Go one meter in the direction he is facing. Then, turn X degrees counter-clockwise.

Constraints

1 \leq X \leq 179

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the number of times Takahashi will do the action before he is at the starting position again.

Sample Input 1

90

Sample Output 1

4

Takahashi's path is a square.

Sample Input 2

1

Sample Output 2

360

Solution in Rust (1.42.0) (judge verdict: Accepted)

use input::Input;

fn main() {
    let mut input = Input::default();

    let x: u32 = input.parse();
    let x = std::f64::consts::PI / 180.0 * x as f64;

    let d = 0.001f64;
    let r = 1.0f64;
    let mut a = 0.0f64;
    let mut b = 0.0f64;
    let mut dest = std::f64::consts::FRAC_PI_2;
    for i in 1..=360 {
        a += r * dest.cos();
        b += r * dest.sin();
        if a.abs() < d && b.abs() < d {
            println!("{}", i);
            break;
        }
        dest += x;
    }
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}