Road Network

시간 제한1초메모리 제한2048 MB

요약
각 도시 i를 (3i+7) mod N번 도시와 잇는 N개의 도로가 주어질 때 그래프의 연결 여부를 판정하고, 연결되지 않았다면 서로 갈 수 없는 두 도시를 출력한다.
난이도

보통10점 중 7점

유형
그래프, 유니온 파인드, 정수론, 수학
정답자
아직 제출이 없습니다

문제

There are NN cities and NN two-way roads in Potokoland. The cities are numbered from 00 to N−1N-1. The roads are also numbered from 00 to N−1N-1. The road number ii connects cities ii and (3⋅i+7) mod N(3 \cdot i + 7) \bmod N, where x mod Nx \bmod N is the remainder from dividing xx by NN.

Determine if it is possible to travel from any city to any other city using the roads. If not, find a pair of cities that are not connected.

입력

The first line contains NN (1≤N≤1061 \le N \le 10^6), the number of cities in Potokoland.

출력

Output the word 'YES' if it is possible to travel from any city to any other city.

Otherwise, output the word 'NO' on the first line. On the second line, output any two cities AA and BB (0≤A,B≤N−10 \le A, B \le N-1; A≠BA \ne B) such that it is impossible to travel from AA to BB using the roads. If there are several possible answers, output any one of them.

예제2

  1. 예제 1

    입력
    4
    
    예상 출력
    NO
    0 1
    
  2. 예제 2

    입력
    6
    
    예상 출력
    YES