#### 문제 정보

- 문제 ID
- 시간 제한
- 메모리 제한
- 제출 횟수
- 정답 횟수 (비율)

#### 문제

Sonny uses a very peculiar pattern when it comes to playing rock-paper-scissors. He likes to vary his moves so that his opponent can’t beat him with his own strategy.

Sonny will play rock (R) on his first game, followed by paper (P) and scissors (S) for his second and third games, respectively. But what if someone else is using the same strategy? To thwart those opponents, he’ll then play paper to beat rock, scissors to beat paper, and rock to beat scissors, in that order, for his 4th through 6th games. After that, he’ll play scissors, rock, and paper for games 7–9 to beat anyone copying his last set of moves. Now we’re back to the original order—rock, paper, scissors—but instead of being predictable and using the same moves, do you know what would be better? You guessed it! Sonny then plays the sequence of moves that would beat anyone trying to copy his whole strategy from his first move, and on it goes…

To recap, in symbolic form, Sonny’s rock-paper-scissors moves look like this:

`R P S PSR SRP PSRSRPRPS SRPRPSPSR PSRSRPRPSSRPRPSPSRRPSPSRSRP ...`

The spaces are present only to help show Sonny’s playing pattern and do not alter what move he’ll play on a certain game.

Naturally, your job is to beat Sonny at his own game! If you know the number of the game that you’ll be playing against Sonny, can you figure out what move you would need to play in order to beat him?

#### 입력

Each line of the input contains a single integer N, 1 ≤ N ≤ 10^{12}, the number of the game you’ll be playing against Sonny. An integer N = 1 indicates it would be Sonny’s first game, N = 7 indicates it would be the 7th game, and so forth. The input terminates with a line with N = 0.

Warning: N may be large enough to overflow a 32-bit integer, so be sure to use a larger data type (i.e. long in Java or long long in C/C++) in your program.

#### 출력

For each test case, output a single line which contains the letter corresponding to the move you would need to play to beat Sonny on that game.

#### 예제 입력

1 7 33 0

#### 예제 출력

P R S

## 답안 번호 #604349

- 문제
- 제출자
- 제출 시간
- 길이
- 수행 시간
- 채점 결과

#### 소스 코드

```
#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
const char ANS[3] = {'P', 'S', 'R'};
unsigned long N;
unsigned long arr[30][2];
int f(unsigned long n) {
if (n < 3) return (int)n;
int index = 0;
for(;;index++) {
if (n < arr[index][1]) break;
}
return (f(n - arr[index][0]) + 1) % 3;
}
int main() {
arr[0][0] = 1;
arr[0][1] = arr[0][0] * 3;
for (int i = 1; arr[i - 1][1] <= 1000000000000; ++i) {
arr[i][0] = arr[i - 1][0] * 3;
arr[i][1] = arr[i][0] * 3;
}
while (1) {
scanf("%lu", &N);
if (N == 0) return 0;
printf("%cn", ANS[f(N - 1)]);
}
return 0;
}
```