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 C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int x;
    scanf("%d", &x);

    int a[22];
    for (int i = 1, j = 0; i <= 120; ++i)
    {
        if (360 % i == 0)
            a[j++] = i;
    }

    int t, ans = 1;

    if (360 % x)
    {
        while (1)
        {
            for (int i = 0; i < 22; i++)
            {
                if ((a[i] <= x / 2) && (a[i + 1] > x / 2))
                {
                    t = i;
                    break;
                }
            }
            ans *= (((360 / a[t]) * (360 / a[t + 1])));
            if (a[t] + a[t + 1] == x)
                break;
            else
                x -= (a[t] + a[t + 1]);
        }
        printf("%d", ans);
    }
    else
        printf("%d", 360 / x);

    return 0;
}