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

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)

Java AC 代码

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 2; i <= n; i++)
for(int a = 2; a < i; a++)
for(int b = a; b < i; b++)
for(int c = b; c < i; c++) {
if(i*i*i == a*a*a + b*b*b + c*c*c) {
System.out.println("Cube = " + i +", Triple = (" + a + "," + b + "," + c +")");
}
}
}
}

poj 1543 Perfect Cubes (暴搜)的更多相关文章

  1. OpenJudge 2810(1543) 完美立方 / Poj 1543 Perfect Cubes

    1.链接地址: http://bailian.openjudge.cn/practice/2810/ http://bailian.openjudge.cn/practice/1543/ http:/ ...

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

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

  3. POJ 1543 Perfect Cubes

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

  4. POJ 1167 The Buses 暴搜+剪枝

    思路: 先把能选的路线都预处理出来 按照能停的车的多少排个序 (剪枝1) 搜搜搜 如果当前剩的车÷当前能停车的多少+deep>=ans剪掉 (剪枝2) //By SiriusRen #inclu ...

  5. POJ 1166 The Clocks (暴搜)

    发现对这样的模拟题根本没啥思路了,本来准备用bfs的.可是结果超时了,这是參考别的人代码写的: #include <stdio.h> #include <iostream> # ...

  6. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  7. POJ 1945 暴搜+打表 (Or 暴搜+判重)

    思路: 呃呃 暴搜+打表 暴搜的程序::稳稳的TLE+MLE (但是我们可以用来打表) 然后我们就可以打表过了 hiahiahia 可以证明最小的那个数不会超过200(怎么证明的我也不知道),然后就直 ...

  8. [POJ 1204]Word Puzzles(Trie树暴搜&amp;AC自己主动机)

    Description Word puzzles are usually simple and very entertaining for all ages. They are so entertai ...

  9. POJ 1414 暴搜

    题意比较复杂 (但是很好理解) 大概意思是给你等边三角形(详见题目中的图). 最后一行有n个数,下一次要填的数是c. 里面预先已经填好了数字.(0为未填) 得分的标准是这个分数的连通块周围没有空的地方 ...

随机推荐

  1. elk5.0 版本遇到的安装问题

    问题1:max_map_count不够大 max virtual memory areas vm.max_map_count [65536] likely too low, increase to a ...

  2. VS 2017 VC++项目出现 LNK1104 无法打开文件"libcmtd.lib" 的解决方法

    今天用VS 2017编译一个以前的VC++动态库项目,出现了一个链接器问题: LNK1104 无法打开文件"libcmtd.lib" . 操作系统版本为:Windows 10 18 ...

  3. 自定义view实现画个闪烁的心

    package com.loaderman.lovecircledemo; import android.support.v7.app.AppCompatActivity; import androi ...

  4. SweetAlert(弹出层插件)

    怀着非常.非常恼火的心情写下这个博文.我深深怀疑有一些人只会瞎粘贴复制别人的博文,自己试都不试就发布到网上,左右看的人想法,就此深通恶绝!! 废话不多说. SweetAlert是一个简洁好用的自制Al ...

  5. [Cinder] 存储 Qos

    目录 文章目录 目录 前言 操作步骤 参考文章 前言 Cinder 支持 front-end 和 back-end 两种类型的存储 QoS,前者由 Hypervisor 端实现(e.g. 通过 Lib ...

  6. Linux_系统破坏性修复实验

    目录 目录 修改系统用户密码 grub修复 系统修复 最后 修改系统用户密码 随便介绍一个修改Linux系统用户密码的方法. 步骤: 开机读秒时按任意键 进入grub列表项配置按e 选择系统kerne ...

  7. 阶段3 2.Spring_02.程序间耦合_3 程序的耦合和解耦的思路分析1

    编译时没有对应需要的jar包就报错.这特性就理解为程序的耦合 这种方式,它不是个错误而是个异常.编译的时候没有问题.运行时才会报错. 把注释的代码放开 程序可以正常运行 解决类之前依赖的思路 一个依赖 ...

  8. Flutter异步Future

    一.认识Future 1.创建Future void testFuture(){ Future future = new Future(() => null); future.then((_){ ...

  9. IIS部署网站 HTTP 错误 500.21 - Internal Server Error

    HTTP 错误 500.21 - Internal Server Error处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipel ...

  10. js里面for循环的++i与i++

    首先我们应该都知道++i与i++的区别是: ++i 是先执行 i=i+1 再使用 i 的值,而 i++ 是先使用 i 的值再执行 i=i+1: 然后我们也知道for循环的执行顺序如下: for(A;B ...