C/C++の宿題を片付けます 112代目
■ このスレッドは過去ログ倉庫に格納されています
0434デフォルトの名無しさん
2008/07/10(木) 10:18:16#include<stdio.h>
#include<math.h>
#define EPS 0.01
void hoge(int count_max){
int x, y, z, num, count=0;
int init_y, left_x, left_xy;
if(count_max<=0) return;
for(num=3;;num++){
for(z=sqrt(num-2+EPS);z>0;z--){
left_xy=num-z*z;
init_y=sqrt(left_xy-1+EPS);
if(init_y>z) init_y=z;
for(y=init_y;y>0;y--){
left_x=left_xy-y*y;
x=sqrt(left_x+EPS);
if(x>y) break;
if(x*x==left_x){
printf("%d ( %d %d %d )\n", x*x+y*y+z*z, x, y, z);
if(++count>=count_max) return;
}
}
}
}
}
int main(void){
hoge(20);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています