Perfect Cubes
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 16522   Accepted: 8444

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.

描述

数百年来费马的最后定理,其简单地说明,对于n> 2,没有整数a,b,c> 1使得a ^ n = b ^ n + c ^ n仍然难以确认。(最近的证据被认为是正确的,尽管它仍在进行详细审查。)然而,有可能找到满足“完美立方”方程的大于1的整数a ^ 3 = b ^ 3 + c ^ 3 + d ^ 3(例如,快速计算将显示等式12 ^ 3 = 6 ^ 3 + 8 ^ 3 + 10 ^ 3确实为真)。这个问题要求你编写一个程序来查找满足<= N的这个等式的所有数字{a,b,c,d}。

输入

一个整数N(N <= 100)。

产量

输出应如下所示列出,每行一个完美的立方体,以a的非递减顺序排列(即行应按其值排序)。b,c和d的值也应该在线本身上以非递减顺序列出。确实存在几个可以从多个不同的b,c和d三元组产生的a值。在这些情况下,应首先列出b值较小的三元组。

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

 
#include <stdio.h>
int main(){
    int n,a,b,c,d;
    scanf("%d",&n);
    for(a=2;a<=n;++a)
        for(b=2;b<a;++b)
            for(c=b;c<a;++c)
                for(d=c;d<a;++d)
                    if(a*a*a==b*b*b+c*c*c+d*d*d)
                        printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
    return 0;
}

  

Poj1543的更多相关文章

  1. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

随机推荐

  1. 02 JVM 从入门到实战 | 什么样的对象需要被 GC

    引言 上一篇文章 JVM 基本介绍 我们了解了一些基本的 JVM 知识,本篇开始逐步学习垃圾回收,我们都知道既然叫垃圾回收,那回收的就应该是垃圾,可是我们怎么知道哪些对象是垃圾呢? 哪些对象需要被回收 ...

  2. 从壹开始微服务 [ DDD ] 之九 ║从军事故事中,明白领域命令验证(上)

    烽烟 哈喽大家周二好呀,咱们又见面了,上周末掐指一算,距离 圣诞节 只有 5 周的时间了(如果你还不知道为啥我要提圣诞节这个时间点,可以看看我的第二系列开篇<之一 ║ D3模式设计初探 与 我的 ...

  3. 安全性测试入门:DVWA系列研究(二):Command Injection命令行注入攻击和防御

    本篇继续对于安全性测试话题,结合DVWA进行研习. Command Injection:命令注入攻击. 1. Command Injection命令注入 命令注入是通过在应用中执行宿主操作系统的命令, ...

  4. PMP应考知识点-合同类型以及选择要领

    合同类型的选择貌似是必考知识点,加上对合同类型的了解和选择的要领,对于开展日常工作来讲也是挺有必要的.所以这两天重新回顾并总结了合同的种类和各种类的选择要领,与大家分享. 转走请标明出处  https ...

  5. crontab常用

    --crontab检查是否安装[oracle@rac1 ~]$ rpm -qa | grep crontabcrontabs-1.10-8启动与关闭[oracle@rac1 ~]$ /etc/init ...

  6. Vim中设置括号自动补全

    1.打开用户Vim配置文件:~/.vimrc vim ~/.vimrc 2.输入以下配置: set tabstop=4 inoremap " ""<ESC>i ...

  7. win10彻底禁用自动更新,win10怎样彻底关闭自动更新,永久关闭win10自动更新,win10更新助手

    首先,请广大win10受害者原谅小菜用一个如此长的标题来吸引你们,为了尽最大努力帮助那些饱受win10自动更新折磨的朋友们,小菜不得已出此下策,望见谅! windows 10是一个神奇的操作系统,当你 ...

  8. 如何检测或判断一个文件或字节流(无BOM)是什么编码类型

    前言: 昨天,在文章:终于等到你:CYQ.Data V5系列 (ORM数据层,支持.NET Core)最新版本开源了 中, 不小心看到一条留言: 然后就去该地址看了一下,这一看,顺带折腾了一天. 今天 ...

  9. 【Python实践-5】使用迭代查找一个list中最小和最大值

    # -*- coding: utf-8 -*- #使用迭代查找一个list中最小和最大值,并返回一个tuple #遍历list,找到最小值 def findMinAndMax(L): if L==[] ...

  10. Java数据结构和算法 - 高级排序

    希尔排序 Q: 什么是希尔排序? A: 希尔排序因计算机科学家Donald L.Shell而得名,他在1959年发现了希尔排序算法. A: 希尔排序基于插入排序,但是增加了一个新的特性,大大地提高了插 ...