Counter game Hackerrank
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
unsigned long long n;
scanf("%llu",&n);
unsigned long long k ;
int winner = 1; //1 - richard 0 - louise
while(n!=1)
{
if( n && !(n&(n-1)))
n/=2;
else
{
k = pow(2,floor(log2(n)));
n-=k;
}
if(winner)
winner = 0;
else
winner = 1;
}
if(winner)
printf("Richard\n");
else
printf("Louise\n");
}
return 0;
}
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
unsigned long long n;
scanf("%llu",&n);
unsigned long long k ;
int winner = 1; //1 - richard 0 - louise
while(n!=1)
{
if( n && !(n&(n-1)))
n/=2;
else
{
k = pow(2,floor(log2(n)));
n-=k;
}
if(winner)
winner = 0;
else
winner = 1;
}
if(winner)
printf("Richard\n");
else
printf("Louise\n");
}
return 0;
}
0 Comments:
Post a Comment