Files
project-euler/problem-206.c
2019-03-04 19:46:14 -05:00

40 lines
578 B
C

#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define MIN_NUM 1020304050607080900
#define MAX_NUM 1929394959697989990
int digits[] = {0, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int check(long num)
{
int rem;
int i = 0;
while (num>0) {
rem = num % 10;
if (rem != digits[i])
return FALSE;
num /= 100;
i++;
}
return TRUE;
}
int main(int argc, char **argv)
{
long i = 1010101011; /* while ((i*i) < MIN_NUM) i++; */
while ((i*i) < MAX_NUM) {
if (check(i*i))
break;
i++;
}
printf("The unique integer is %ld and it's square is %ld\n", i, i*i);
return 0;
}