1.链接地址:

http://bailian.openjudge.cn/practice/2810/

http://bailian.openjudge.cn/practice/1543/

http://poj.org/problem?id=1543

2.题目:

Perfect Cubes
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 13190   Accepted: 6995

Description

For hundreds of years Fermat's Last Theorem, which stated simply that for n > 2 there exist no integers a, b, c > 1 such that a^n = b^n + c^n, has remained elusively unproven. (A recent proof is believed to be correct, though it is still undergoing scrutiny.) It is possible, however, to find integers greater than 1 that satisfy the "perfect cube" equation a^3 = b^3 + c^3 + d^3 (e.g. a quick calculation will show that the equation 12^3 = 6^3 + 8^3 + 10^3 is indeed true). This problem requires that you write a program to find all sets of numbers {a,b,c,d} which satisfy this equation for a <= N.

Input

One integer N (N <= 100).

Output

The output should be listed as shown below, one perfect cube per line, in non-decreasing order of a (i.e. the lines should be sorted by their a values). The values of b, c, and d should also be listed in non-decreasing order on the line itself. There do exist several values of a which can be produced from multiple distinct sets of b, c, and d triples. In these cases, the triples with the smaller b values should be listed first.

Sample Input

24

Sample Output

Cube = 6, Triple = (3,4,5)
Cube = 12, Triple = (6,8,10)
Cube = 18, Triple = (2,12,16)
Cube = 18, Triple = (9,12,15)
Cube = 19, Triple = (3,10,18)
Cube = 20, Triple = (7,14,17)
Cube = 24, Triple = (12,16,20)

Source

3.思路:

枚举+打表(减少计算次数)

注意a要升序排列,然后b,c,d再升序排列

4.代码:

 #include <iostream>
#include <cstdio> #define START_N 2 using namespace std; int main()
{
int n;
cin>>n; int *arr_cube = new int[n]; int i,j,k,p;
for(i = START_N; i <= n; ++i)
{
arr_cube[i - START_N] = i * i * i;
for(j = START_N; j <= i; ++j)
{
for(k = j; k <= i; ++k)
{
for(p = k; p <= i; ++p)
{
if(arr_cube[i - START_N] == arr_cube[j - START_N]
+ arr_cube[k - START_N] + arr_cube[p - START_N])
{
cout<<"Cube = "<<i<<", Triple = ("<<j<<","<<k<<","<<p<<")"<<endl;
}
}
}
} } delete [] arr_cube;
return ;
}

OpenJudge 2810(1543) 完美立方 / Poj 1543 Perfect Cubes的更多相关文章

  1. 2810:完美立方-poj

    2810:完美立方 总时间限制:  1000ms 内存限制:  65536kB 描述 形如a3= b3 + c3 + d3的等式被称为完美立方等式.例如123= 63 + 83 + 103 .编写一个 ...

  2. OpenJudge计算概论-完美立方【暂时就想到了枚举法了】

    /*===================================== 完美立方 总时间限制: 1000ms 内存限制: 65536kB 描述 a的立方 = b的立方 + c的立方 + d的立 ...

  3. POJ 2810:完美立方

    原题链接 总时间限制: 1000ms 内存限制: 65536kB 描述 形如\(a^{2}\)= \(b^{2}\) + \(c^{2}\) + \(d^{2}\)的等式被称为完美立方等式.例如123 ...

  4. poj 1543 Perfect Cubes(注意剪枝)

    Perfect Cubes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14901   Accepted: 7804 De ...

  5. POJ 1543 Perfect Cubes

    Perfect Cubes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12595   Accepted: 6707 De ...

  6. poj 1543 Perfect Cubes (暴搜)

    Perfect Cubes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15302   Accepted: 7936 De ...

  7. Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配)

    Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配) Description 农夫约翰上个 ...

  8. OpenJ_Bailian 2810 完美立方

    题目地址: https://vjudge.net/problem/OpenJ_Bailian-2810 形如a3= b3 + c3 + d3的等式被称为完美立方等式.例如123= 63 + 83 + ...

  9. Openjudge-计算概论(A)-完美立方

    描述: a的立方 = b的立方 + c的立方 + d的立方为完美立方等式.例如12的立方 = 6的立方 + 8的立方 + 10的立方 .编写一个程序,对任给的正整数N (N≤100),寻找所有的四元组 ...

随机推荐

  1. NSDateFormatter 问题

    NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init]; NSString *inputDateStr = @&quo ...

  2. ThinkPHP 获取配置文件中的值

    C('SPECIAL_USER'):获取配置文件中的值 存入数组

  3. [Server Running] [Node.js, PM2] Using PM2 To Keep Your Node Apps Alive

    PM2 is a production process manager for Node.js applications with a built-in load balancer. It allow ...

  4. [AngularJS] Reusable directive, require from parent controller

    Glorious Directives for Our Navigation NoteWrangler navigation has now been broken into two parts: t ...

  5. leetcode解决问题的方法||Integer to Roman问题

    problem: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range ...

  6. insert erase和replace的例子

    9.43 编写一个函数,接受三个string参数s.oldVal和newVal.使用迭代器及insert和erase函数将s中所有oldval替换为newVal.测试程序,用它替换通用的简写形式,如, ...

  7. iOS开发几年了,你清楚OC中的这些东西么1

    前言 几年前笔者是使用Objective-C进行iOS开发, 不过在两年前Apple发布swift的时候,就开始了swift的学习, 在swift1.2发布后就正式并且一直都使用了swift进行iOS ...

  8. Debian 7 安装Firefox

    Debian 7默认自带的浏览器叫做 iceweasel,据维基百科介绍是Mozilla Firefox浏览器的一个再发布版,从Debian 4 开始默认安装. 本文内容:安装Firefox.安装Fl ...

  9. Adroid_Spinner_ArrayAdapter

    XML布局文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  10. jquery用on代替bind(),live(),delegate()的方法

    Js的功能确实非常强大,奈何我一个php程序员一直在js上没有投入足够的精力去研究,每次遇到不会的都是去百度,以后有时间真的应该买本书系统的学习一下 // Bind $( "#members ...