Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef unsigned char _bool;
- #define TRUE 1
- #define FALSE 0
- #define MAXSIZE 1000
- _bool isRtri(int a, int b , int c){
- _bool rtf = FALSE;
- if(a*a + b*b == c*c) rtf = TRUE;
- if(a*a + c*c == b*b) rtf = TRUE;
- if(c*c + b*b == c*c) rtf = TRUE;
- if(a == 0 || b == 0 || c == 0) rtf = FALSE;
- return rtf;
- }
- int main (void){
- int as = 0;
- int bs = 0;
- int cs = 0;
- int triCnt=0;
- int sums=0;
- int maxcnt[2]={0};
- for(sums=1 ; sums<=MAXSIZE ; sums++){
- for(as = 1 ; as <= MAXSIZE ; as++){
- for(bs = 1 ; bs <= MAXSIZE ; bs++){
- cs = sums - (as + bs);
- if(as + bs + cs >= MAXSIZE || cs<=0) break;
- if(isRtri(as,bs,cs) == TRUE){
- triCnt++;
- }
- }
- }
- if(triCnt != 0){
- if(maxcnt[1] <= triCnt/4){
- maxcnt[0] = sums;
- maxcnt[1] = triCnt/4;
- }
- triCnt=0;
- }
- }
- printf("%d\n",maxcnt[0] ); /* => 840 */
- return 0;
- }
Add Comment
Please, Sign In to add comment