#include <stdio.h> #include <limits.h> struct FourNum { int GotIt; long C1,C2,C3,C4; }; struct FourNum find4cub(long Val) { long nb1,nb2; long SomCub, Cub1, Cub2; struct FourNum TheRes; TheRes.C1 = TheRes.C2 = TheRes.C3 = TheRes.C4 = 0; TheRes.GotIt = 0; SomCub = 0; for(nb1=1;nb1<Val;nb1++) { Cub1 = nb1 * nb1 * nb1 ; if(Cub1 >= Val) break; for(nb2=1;nb2<Val;nb2++){ Cub2 = nb2 * nb2 * nb2 ; SomCub = Cub1 + Cub2 ; if(SomCub > Val) break; if(SomCub == Val) { if(!TheRes.GotIt){ TheRes.C1=nb1; TheRes.C2=nb2; TheRes.GotIt++; } else if(TheRes.GotIt == 1) { if(TheRes.C2 == nb1) continue; else { TheRes.C3 = nb1; TheRes.C4 = nb2; TheRes.GotIt++; } } } if(TheRes.GotIt == 2) break; } if(TheRes.GotIt == 2) break; } return TheRes; } main(int argc, char *argv[]) { unsigned long Candidat; struct FourNum RR; int res,nb,init; if(argc>1){ res = sscanf(argv[1],"%d",&init); if(res != 1) fprintf(stderr,"Syntaxe : %s valeur entiere initiale\n", argv[0]); } for(Candidat=init; Candidat<LONG_MAX; Candidat++){ RR = find4cub(Candidat); if((RR.GotIt == 2){ printf("le taxi de hardy avait pour numero %ld\n", Candidat); printf("qui se decompose selon les deux paires de cubes" " %ld %ld et %ld %ld\n", RR.C1, RR.C2, RR.C3, RR.C4); break; } } return 0; }