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

  1. 24

Sample Output

  1. Cube = 6, Triple = (3,4,5)
  2. Cube = 12, Triple = (6,8,10)
  3. Cube = 18, Triple = (2,12,16)
  4. Cube = 18, Triple = (9,12,15)
  5. Cube = 19, Triple = (3,10,18)
  6. Cube = 20, Triple = (7,14,17)
  7. Cube = 24, Triple = (12,16,20)
    题目大意:给定一个数n,三个数a,b,c大于1,问n以内有多少个数字满足n^3 = a^3 + b^3 + c^3
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. int ans[];
  7. int visted[];
  8. int selected[];
  9.  
  10. void DFS(int n, int index)
  11. {
  12. if (index == )
  13. {
  14. if (n * n * n == ans[] * ans[] * ans[] + ans[] * ans[] * ans[] + ans[] * ans[] * ans[] && selected[ans[]] * selected[ans[]] * selected[ans[]] == )
  15. {
  16. printf("Cube = %d, Triple = (%d,%d,%d)\n", n, ans[], ans[], ans[]);
  17. selected[ans[]] = selected[ans[]] = selected[ans[]] = ;
  18. }
  19. return;
  20. }
  21. for (int i = ; i < n; i++)
  22. {
  23. if (!visted[i])
  24. {
  25. visted[i] = ;
  26. ans[index] = i;
  27. DFS(n, index + );
  28. visted[i] = ;
  29. }
  30. }
  31. }
  32.  
  33. int main()
  34. {
  35. int n;
  36. scanf("%d", &n);
  37. for (int i = ; i <= n; i++)
  38. {
  39. memset(visted, , sizeof(visted));
  40. memset(selected, , sizeof(selected));
  41. DFS(i, );
  42. }
  43. return ;
  44. }

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. H5网站加载速度优化总结

    1. 在代码文件结构 尽量优化的同时,能力再强已经到极限了,但你服务器辣鸡,搭配不当,你代码优化上天 也是徒劳啊. 2.你不怎么优化, 服务器 各种技术配置到位的话, now你也看到了,我一个系统首页 ...

  2. BootStrap的基本使用

    bootstrap 现成的css样式,直接调用类作用是快速写出页面又称UI框架Bootstrap中文网LESS是预处理器CSS预处理器定义了一种新的语言,基本的思想是用一种专门的编程语言,开发者只需要 ...

  3. Android 滑动RecyclerView时隐藏部分控件

    在使用RecyclerView控件时,上下拖动控件时的时候,需要实时的隐藏与显示部分控件,已到达很好的用户体验.   原理很简单,当RecyclerView拖动至最上层时显示控件,当RecyclerV ...

  4. cp参数详解

    -a 相当于pdr的意思 -d 若原文件为连接文件,则复制链接文件属性,而非文件本身 -f 强制复制,有重复时,不询问用户,而直接强制复制 -i 目标文件存在的话,先询问 -p 与文件的属性一起复制 ...

  5. K-means、KNN学习笔记

    1.K-means:聚类算法,无监督 输入:k, data[n]; (1) 选择k个初始中心点,例如c[0]=data[0],…c[k-1]=data[k-1]; (2) 对于data[0]….dat ...

  6. (十)maven之排除冲突jar包

    排除冲突jar包 jar包冲突 <dependencies> <dependency> <groupId>org.springframework</group ...

  7. Objective-C分类 (category)和扩展(Extension) 的区别

    http://blog.csdn.net/yhawaii/article/details/6992094 http://blog.163.com/wangy_0223/blog/static/4501 ...

  8. 树形dp——Tree2cycle

    一.问题描述(题目链接) 给你一棵树,删除或添加一条边的费用都是1,问使它变成一个环的最小费用. 二.解题思路 回溯法,然后回溯的时候的当前节点度数>2(如果是成环的话肯定就是2或者小于2)就把 ...

  9. 实 Jordan 标准型和实 Weyr 标准型

    将学习到什么 本节讨论关于实矩阵的实形式的 Jordan 标准型,也讨论关于复矩阵的另外一种形式的 Jordan 标准型,因为它在与交换性有关的问题中很有用.   实 Jordan 标准型 假设 \( ...

  10. iOS UI 设计

    优设 http://www.uisdc.com Sketch http://www.sketchcn.com