求方程解问题
測試你是否和LTC水平一樣高
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14886????Accepted Submission(s): 4890
你的任務是:
計算方程x^2+y^2+z^2= num的一個正整數解。
?
Input 輸入數據包含多個測試實例,每個實例占一行,僅僅包含一個小于等于10000的正整數num。?
Output 對于每組測試數據,請按照x,y,z遞增的順序輸出它的一個最小正整數解,每個實例的輸出占一行,題目保證所有測試數據都有解。?
Sample Input 3?
Sample Output 1 1 1 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 int main() 6 { 7 int x,y,num,i,flag=0,temp; 8 double z; 9 while(scanf("%d",&num)!=EOF) 10 { 11 flag=0; 12 for(x=1;x<=sqrt(num);x++) 13 { 14 for(y=1;y<=sqrt(num-x*x);y++) 15 { 16 temp=num-x*x-y*y; 17 z=sqrt(temp); /*求平方根*/ 18 if(abs(z-int(z))<=0.000001&&int(z)) /*判斷平方根是否為整數*/ 19 { 20 printf("%d %d %d\n",x,y,int(z)); 21 flag=1; 22 break; 23 } 24 } 25 if(flag) 26 break; 27 } 28 } 29 }?
轉載于:https://www.cnblogs.com/a1225234/p/4690431.html
總結
- 上一篇: Ubuntu10.04下安装Ns2的一系
- 下一篇: 短信备份(原)