Skip to content

Instantly share code, notes, and snippets.

Created May 25, 2012 05:22
Show Gist options
  • Save anonymous/2785930 to your computer and use it in GitHub Desktop.
Save anonymous/2785930 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
long long n;
char beat(char c) {
if( c == 'R' ) return 'P';
if( c == 'P' ) return 'S';
return 'R';
}
char solve(long long size, int block, long long pos) {
if( size == 1 ) {
if( block == 1 ) return 'R';
if( block == 2 ) return 'P';
return 'S';
}
if( block == 1 ) {
if( size == 3 )
return solve(size/3, pos, 1);
return solve(size/3, (pos-1)/(size/3)+1, (pos-1)%(size/3)+1);
}
if( block == 2 ) {
return beat( solve(size, block-1, pos) );
}
if( block == 3 ) {
return beat( solve(size, block-1, pos) );
}
}
int main()
{
while( true ) {
scanf("%lld", &n);
if( n == 0ll ) break;
long long t = 1ll;
while( t*3ll < n ) t*=3ll;
printf("%c\n", beat(solve(t, (n-1)/t+1, (n-1)%t+1)));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment