今日一言:
谢谢你,成为我前进的理由。
——《言叶之庭》
数据结构 —— 约瑟夫环
C语言实现
/*********************************************************************************
*
* 阅兵方阵 (暴力破解)
* create: 2020年5月24日 22点56分
* author: LOS(小鱼)
*
* *******************************************************************************/
#include<stdio.h>
void main(){
int troop[12][2];
int n = 160000;
int x,y,count,i;
for ( ; n < 200000 ; n++ ){
count = 0;
for ( x = 1 ; x < 10000 ; x++ ){
for ( y = 1 ; y < 10000 ; y++ ){
if( x*x + y*y == n ){
troop[count][0] = x;
troop[count][1] = y;
count++;
if( count == 12 ){
for ( i=0 ; i<12; i++ ){
printf("第%d支队伍 --> %d^2 + %d^2 = %d + %d = %d\n",i+1,
troop[i][0],troop[i][1],troop[i][0]*troop[i][0],troop[i][1]*troop[i][1],n);
}
return;
}
}
}
}
}
}
运行结果
第1支队伍 --> 5^2 + 400^2 = 25 + 160000 = 160025
第2支队伍 --> 125^2 + 380^2 = 15625 + 144400 = 160025
第3支队伍 --> 128^2 + 379^2 = 16384 + 143641 = 160025
第4支队伍 --> 229^2 + 328^2 = 52441 + 107584 = 160025
第5支队伍 --> 236^2 + 323^2 = 55696 + 104329 = 160025
第6支队伍 --> 244^2 + 317^2 = 59536 + 100489 = 160025
第7支队伍 --> 317^2 + 244^2 = 100489 + 59536 = 160025
第8支队伍 --> 323^2 + 236^2 = 104329 + 55696 = 160025
第9支队伍 --> 328^2 + 229^2 = 107584 + 52441 = 160025
第10支队伍 --> 379^2 + 128^2 = 143641 + 16384 = 160025
第11支队伍 --> 380^2 + 125^2 = 144400 + 15625 = 160025
第12支队伍 --> 400^2 + 5^2 = 160000 + 25 = 160025
--------------------------------
Process exited after 5.712 seconds with return value 50
请按任意键继续. . .