求解方程A5+B5+C5+D5+E5=F5
方程A5+B5+C5+D5+E5=F5刚好有一个满足0<A≤B≤C≤D≤E≤F≤75的整数解。请编写一个求出该解的程序:
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 }
输出:
注:如果条件变为0≤A≤B≤C≤D≤E≤F≤75 则有很多解,输出如下:
Well begun is half done ...