import java.util.*;
class Solution {
public static void main(String[] args) {
Solution s = new Solution();
tester(45,7,s);
tester(125,229,s);
}
public static void tester(int n, int result,Solution s) {
int ret = s.solution(n);
if(ret == result) {
System.out.println("OK");
}
else {
System.out.println("NG");
}
}
public int solution(int n) {
int answer = 0;
StringBuilder sb = new StringBuilder();
int r=0;
while (n!=0) {
r = n%3;
n = n/3;
sb.append(r);
}
sb.reverse();
String jinsu3 = sb.toString();
for(int i=0 ; i<jinsu3.length() ; i++) {
String sbstr = jinsu3.substring(i,i+1);
answer += (int)Math.pow(3,i) * Integer.parseInt(sbstr);
}
return answer;
}
}