方程A5+B5+C5+D5+E5=F5恰好有一個知足0<A≤B≤C≤D≤E≤F≤75的整數解。請編寫一個求出該解的程序:ide
1 using System; 2 3 namespace ReverseTheExponentiation 4 { 5 class Program 6 { 7 static void Main(string[] args) 8 { 9 Program P = new Program(); 10 P.ReverseTheExponentiation(); 11 } 12 13 void ReverseTheExponentiation() 14 { 15 int A, B, C, D, E, F; 16 for (F = 75; F > 0; F--) 17 { 18 for (E = 1; E <= F; E++) 19 { 20 for (D = 1; D <= E; D++) 21 { 22 for (C = 1; C <= D; C++) 23 { 24 for (B = 1; B <= C; B++) 25 { 26 for (A = 1; A <= B; A++) 27 { 28 if (Math.Pow(A, 5) + Math.Pow(B, 5) + Math.Pow(C, 5) + Math.Pow(D, 5) + Math.Pow(E, 5) == Math.Pow(F, 5)) 29 { 30 Console.WriteLine("A,B,C,D,E,F are: {0},{1},{2},{3},{4},{5}", A, B, C, D, E, F); 31 } 32 } 33 } 34 } 35 } 36 } 37 } 38 } 39 } 40 }
輸出:spa
注:若是條件變爲0≤A≤B≤C≤D≤E≤F≤75 則有不少解,輸出以下:3d