Hello,
I'm trying to solve an ACM problem "Light, more light". The problem is actually solved, but I can get it accepted. So browsing Internet I found a C code, which is accepted:
#include<stdio.h>
#include<math.h>
int main(void) {
long long int n;
while(scanf("%lld", &n)==1) {
if(n==0)
break;
else if( (long long int)sqrt((double)n) * (long long int)sqrt((double)n) == n)
printf("yes\n");
else
printf("no\n");
}
return 0;
}
However, it doesnt' work in Eclipse's console (MinGW GCC toolchain). Why is that?
But the main problem is not that. The task states, that the number won't exceed 2^32 - 1, so in my own solution I used unsigned int:
#include <stdio.h>
#include <math.h>
int main()
{
unsigned int n;
while (scanf("%d", &n) == 1)
{
if (n == 0)
break;
else
{
unsigned int root = (unsigned int)sqrt((double)n);
if (root*root != n)
{
printf("no\n");
}
else
{
printf("yes\n");
}
}
}
return 0;
}
... which is almost the same, works fine in Eclipse's console, but doesn't get accepted on ACM neither as ANSI C, nor as C++. Can anyone tell me where is the mistake?