-
-
Save nsmaciej/9144533 to your computer and use it in GitHub Desktop.
AIPO2013 q2 bad solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <stdbool.h> | |
bool appToParis(unsigned self[3][2], unsigned len, unsigned val1, unsigned val2){ | |
unsigned i = 0; | |
for(i = 0; i<len; ++i){ | |
if((self[i][0] == val1 && self[i][1] == val2) || (self[i][0] == val2 && self[i][1] == val1)){ | |
return false; | |
} | |
} | |
self[len][0] = val1; | |
self[len][1] = val2; | |
return true; | |
} | |
int main(void){ | |
unsigned num; //to be found | |
unsigned found = 0; //found already | |
unsigned total; //resukls to check | |
unsigned first; //x | |
float tmp; //sqrt res | |
unsigned last = 0; //last num | |
unsigned lastn = 0; //number itself | |
unsigned pairs[3][2]; | |
unsigned pairl = 0; | |
scanf("%u",&num); | |
for(total = 3; found < num; ++total){ | |
for(first = 3; first < total; ++first){ | |
tmp = sqrt(total*total - first*first); | |
if((int)tmp == tmp){ | |
if(lastn == total){ | |
pairl += appToParis(pairs, pairl, first, (unsigned)tmp); | |
if(pairl > 1){ | |
//printf("\t%u. (%u, %f, %u)\n",found, first,tmp,total); | |
///printf("%u^2 + %f^2 = %u^2\n",first,tmp,total); | |
printf("%u\n",total); | |
break; | |
} | |
}else{ | |
++found; | |
lastn = total; | |
pairl = 0; | |
last = 0; | |
} | |
//printf("\t%u. (%u, %f, %u)\n",found, first,tmp,total); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment