C ++ basic algorithm learning-perfect cube, basic algorithm
An equation like a 3 = B 3 + c 3 + d 3 is called a perfect cubic equation. For example
12 3 = 6 3 + 8 3 + 10 3. Write a program for any positive integer N
(N ≤ 100), find all the four tuples (a, B, c, d), make a 3 =
B 3 + c 3 + d 3, where a, B, c, d is greater than 1, less than or equal to N, and
B <= c <= d.
Input
A positive integer N (N ≤ 100 ).
Output
Each row outputs a perfect cube. Output Format:
Cube = a, Triple = (B, c, d)
Here, the positions of a, B, c, and d are substituted with the actual values of the four tuples.
# Include <iostream> # include <math. h> using namespace std; int main () {int a, B, c, d, N; cout <"Enter the value of N:" <endl; cin> N; for (a = 2; a <= N; a ++) {for (B = 1; B <= A-1; B ++) {for (c = B; c <= A-1; c ++) {for (d = c; d <= A-1; d ++) {if (pow (, 3) = (pow (B, 3) + pow (c, 3) + pow (d, 3) {// cout <": "<a <(a ^ 3) <" -- "<a * a <endl; cout <"Cube =" <a <", Triple (" <B <"," <c <"," <d <") "<endl ;}}}return 0 ;}