We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
unsigned int isPowerOfTwo(unsigned long long int n) {
return (n && (!(n & (n-1))));
}
unsigned long long int largestPowerOfTwo(unsigned long long int n) {
while(n & (n-1)) {
n = n & (n-1);
}
return n;
}
void CG(unsigned long long int n) {
if(n == 1) {
printf("Richard\n");
}
else {
int lr = 0;
while (n != 0) {
if(isPowerOfTwo(n)) {
//If N is a power of 2, reduce the counter by half of N
n = n / 2;
}
else {
//if N is not a power of 2, reduce the counter by the largest power of 2 less than N
n -= largestPowerOfTwo(n);
}
lr++;
}
if(lr%2)
printf("Richard\n");
else
printf("Louise\n");
}
}
int main() {
int T;
unsigned long long int N;
scanf("%d", &T);
for(int i = 0; i < T; i++) {
scanf("%llu", &N);
CG(N);
}
return 0;
}
Counter game
You are viewing a single comment's thread. Return to all comments →