Hour Hand and Minute Hand

Interview

Time limit1sMemory limit128 MB

Summary
Given an integer A, decide whether the hour and minute hands of a ticking clock can ever form an angle of exactly A degrees. Read A until EOF.
Level

Medium4 of 10

Topics
Math, Number theory, Implementation, Brute force
Solved
No attempts yet

Problem

The clock hanging in Sanggeun's room is a perfect circle, with an hour hand and a minute hand rotating around its center. The hour hand shows the hour and the minute hand shows the minutes. Along the rim there are 6060 tick marks placed at equal intervals, and the gap between any two neighboring ticks is the same.

The minute hand advances to the next tick once every minute, and the hour hand advances to the next tick once every 1212 minutes. Thus after one hour (6060 minutes) the hour hand moves five ticks. Whenever the hour or the minute changes, both hands jump straight to the next tick. In other words, the hour hand and the minute hand always point exactly at some tick and never point between two ticks.

Midnight is the moment when both hands point at the topmost tick at the same time, representing 00 hours and 00 minutes. Starting from that state, after 1212 hours (720720 minutes) the two hands return to the same position, and this motion repeats forever.

There are moments when only the minute hand moves while the hour hand stays put, but whenever the hour hand moves, the minute hand always moves as well.

Sanggeun loves geometry, so every time he looks at the clock he computes the angle between the hour hand and the minute hand and writes it down. After several years his paper was covered with a huge number of angles, and he noticed that some angles appear again and again while others never appear at all. For example, at 33 o'clock and at 99 o'clock the angle between the two hands is 9090 degrees, but there is no time at which they form 6565 degrees.

Given an integer AA with 0≤A≤1800 \le A \le 180, write a program that determines whether there exists a time at which the angle between the hour hand and the minute hand of Sanggeun's clock is exactly AA degrees.

Input

The input consists of several test cases. Each test case is a single line containing an integer AA (0≤A≤1800 \le A \le 180). The input continues until the end of file.

Output

For each test case, print Y on its own line if there is a time at which the angle between the hour and minute hands is AA degrees, and N otherwise.

Examples2

  1. Example 1

    Input
    90
    65
    66
    67
    128
    0
    180
    
    Expected output
    Y
    N
    Y
    N
    N
    Y
    Y
    
  2. Example 2

    Input
    5
    6
    7
    
    Expected output
    N
    Y
    N