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

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) 题意:找出2到n中,所有满足a^3=b^3+c^3+d^3的a,b,c,d的数
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 2002000
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
int n,m,j,i,t,k,l;
int vis[1000];
int a[150];
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
a[i]=pow(i,3);
for(i=6;i<=n;i++)
{
memset(vis,0,sizeof(vis));
for(j=2;j<i;j++)
{
if(a[i]<a[j]+a[j+1]+a[j+2])
break;
for(k=j;k<i;k++)
{
if(a[i]<a[j]+a[k]+a[k+1]) break;
for(l=k;l<i;l++)
{
if(a[i]==a[j]+a[k]+a[l])
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",i,j,k,l);
}
}
}
}
}
}
return 0;
}

  

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: 12595   Accepted: 6707 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 1011 Sticks (DFS+剪枝)

    Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127771   Accepted: 29926 Descrip ...

  7. POJ 1011 Sticks(dfs+剪枝)

    http://poj.org/problem?id=1011 题意:若干个相同长度的棍子被剪成若干长度的小棍,求每根棍子原来的可能最小长度. 思路:很经典的搜索题. 我一开始各种超时,这题需要很多剪枝 ...

  8. POJ 1011 Sticks 【DFS 剪枝】

    题目链接:http://poj.org/problem?id=1011 Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissio ...

  9. poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】

    题目:  http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...

随机推荐

  1. group by的SQL语句

    有一张项目表 CREATE TABLE [ProjectTable] ( [ProjectID] NVARCHAR(16) NOT NULL, [ProjectName] NVARCHAR(20) N ...

  2. Setup Oracle 11gR2 for Redhat Linux AS 4 Update 7 x64

    Setup Oracle 11gR2 for Redhat Linux AS 4 Update 7 x64 1. checking linux version. [root@localhost ~]# ...

  3. awk 传入外部参数

    awk 传入外部参数 num1=1.1 num2=2.2 result=$(awk -v n1=$num1 -v n2=$num2 'BEGIN{print (n2>n1)?1:0}')

  4. sendmessage()模拟鼠标点击

    {鼠标软模拟:好处就是不会真的移动鼠标 开始按钮 坐标 x=386y=387 }sendmessage(hookHwnd,messages.WM_LBUTTONDOWN ,0,$0180017A); ...

  5. LA 3263 (平面图的欧拉定理) That Nice Euler Circuit

    题意: 平面上有n个端点的一笔画,最后一个端点与第一个端点重合,即所给图案是闭合曲线.求这些线段将平面分成多少部分. 分析: 平面图中欧拉定理:设平面的顶点数.边数和面数分别为V.E和F.则 V+F- ...

  6. 面向函数范式编程(Functional programming)

    函数编程(简称FP)不只代指Haskell Scala等之类的语言,还表示一种编程思维,软件思考方式,也称面向函数编程. 编程的本质是组合,组合的本质是范畴Category,而范畴是函数的组合. 首先 ...

  7. liux之sed用法

    sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法sed命令行格式为:         sed ...

  8. (5)Quartz学习

    原文:http://blog.csdn.net/zxl315/article/details/10879927 介绍Quartz Quartz是一个开源的任务调度系统,它能用来调度很多任务的执行. 运 ...

  9. Ubuntu消息菜单(MessagingMenu)API

    应用程序可以注册在消息菜单里显示消息,它也可以使用全局聊天状态项目. 注册 应用程序要在消息菜单里显示消息,必须满足以下条件: $HOME/.config/indicators/messages/ap ...

  10. Android中TabHost嵌套TabHost

    在嵌套TabHost时,先后遇到了以下情况: 问题1:内部TabHos无显示,只显示了其中的一个Activity: 解决:按下文比对主子TabHos的布局文件和java文件并修改: 问题2:如上所做后 ...