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

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)
题目大意:给定一个数n,三个数a,b,c大于1,问n以内有多少个数字满足n^3 = a^3 + b^3 + c^3。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std; int ans[];
int visted[];
int selected[]; void DFS(int n, int index)
{
if (index == )
{
if (n * n * n == ans[] * ans[] * ans[] + ans[] * ans[] * ans[] + ans[] * ans[] * ans[] && selected[ans[]] * selected[ans[]] * selected[ans[]] == )
{
printf("Cube = %d, Triple = (%d,%d,%d)\n", n, ans[], ans[], ans[]);
selected[ans[]] = selected[ans[]] = selected[ans[]] = ;
}
return;
}
for (int i = ; i < n; i++)
{
if (!visted[i])
{
visted[i] = ;
ans[index] = i;
DFS(n, index + );
visted[i] = ;
}
}
} int main()
{
int n;
scanf("%d", &n);
for (int i = ; i <= n; i++)
{
memset(visted, , sizeof(visted));
memset(selected, , sizeof(selected));
DFS(i, );
}
return ;
}

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: 15302   Accepted: 7936 De ...

  4. POJ 3398 Perfect Service(树型动态规划,最小支配集)

    POJ 3398 Perfect Service(树型动态规划,最小支配集) Description A network is composed of N computers connected by ...

  5. POJ 3905 Perfect Election(2-sat)

    POJ 3905 Perfect Election id=3905" target="_blank" style="">题目链接 思路:非常裸的 ...

  6. POJ 3398 Perfect Service --最小支配集

    题目链接:http://poj.org/problem?id=3398 这题可以用两种上述讲的两种算法解:http://www.cnblogs.com/whatbeg/p/3776612.html 第 ...

  7. HDOJ 1334 Perfect Cubes(暴力)

    Problem Description For hundreds of years Fermat's Last Theorem, which stated simply that for n > ...

  8. POJ 1730 Perfect Pth Powers(暴力枚举)

    题目链接: https://cn.vjudge.net/problem/POJ-1730 题目描述: We say that x is a perfect square if, for some in ...

  9. POJ 3905 Perfect Election (2-Sat)

    Perfect Election Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 438   Accepted: 223 De ...

随机推荐

  1. 《高性能MySQL》读书笔记之 MySQL锁、事务、多版本并发控制的基础知识

    1.2 并发控制 1.2.1 读写锁 在处理并发读或写时,通过实现一个由两种类型的锁组成的锁系统来解决问题.这两种类型的锁通常被称为 共享锁(shared lock) 和 排它锁(exclusive ...

  2. poj2135 最小费用流

    添加超级源点(与点1之间的边容量为2,权值为0)和超级汇点(与点N之间的边容量为2,权值为0),求流量为2的最小费用流.注意是双向边. #include <iostream> #inclu ...

  3. Android 坑爹问题

    A/art: art/runtime/jdwp/jdwp_event.cc:] Check failed: Thread::Current() != GetDebugThread() (Thread: ...

  4. nconf修改密码

    修改nconf登录界面密码 [root@Cnyunwei config]# vi .file_accounts.php <?php/*## User/Password file for simp ...

  5. 洛谷 P2068 统计和

    题目描述 给定一个长度为n(n<=100000),初始值都为0的序列,x(x<=10000)次的修改某些位置上的数字,每次加上一个数,然后提出y (y<=10000)个问题,求每段区 ...

  6. iOS打包上传app store各种问题解决总结

    问题1 this action could not be completed. try again 问题2 there was an error sending data to the iTunes ...

  7. docker安装Tensorflow并使用jupyter notebook

    目前网上提供的大多数的方法都是如下: docker pull tensorflow/tensorflow docker run -it -p : tensorflow/tensorflow 但是按照步 ...

  8. django 2.0 + pycharm2017 出现的问题

    在创建完成app之后,在models文件里创建两个类:BlogType , Blog, 创建超级用户,注册admin,在登陆admin之后发现,发现 BlogType , Blog,并没有导入到adm ...

  9. python之道07

    2.用户输入一个数字,判断一个数是否是水仙花数. 水仙花数是一个三位数, 三位数的每一位的三次方的和还等于这个数. 那这个数就是一个水仙花数, 例如: 153 = 1******3 + 5****** ...

  10. strchr函数

    函数原型:extern char *strchr(char *str,char character) 参数说明:str为一个字符串的指针,character为一个待查找字符.         所在库名 ...