Wednesday, 1 July 2015

TIPTOP

Standard

Tip Top Game

Link to the question: TIPTOP

HINT :

The question asks tells us to find the divisors of a given number and find the winner. Winner is the person who takes the last divisor. So it can very well understood that since Alim plays first, in order to him to win there must be odd number of divisors of the given number else he loses. 
By doing some paper work you will see that all the numbers which are a perfect square have odd number of divisors else they even number of divisors.

SOURCE CODE:

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
int t ;
scanf("%d", &t);
int c = 1;
while(t--)
{
long long int num;
scanf("%lld", &num);
long long int srt = sqrt(num) ;
if( srt*srt == num )
printf("Case %d: Yes\n", c);
else
printf("Case %d: No\n", c);
c++;
}
}

1 comment: