C ++ basic algorithm learning-perfect cube, basic algorithm

Source: Internet
Author: User

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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.