hdu 1334 Perfect Cubes

题目的意思是给出一个数N,寻找a,b,c,d使得a^3=b^3+c^3+d^3成立,其中a<=N,1<b<c<d。


#include<cstdio>

int main(){
    int n,a,b,c,d;
    while(~scanf("%d",&n)){
        for(a=6;a<=n;a++){//样例中a最小为6
            for(b=2;b<a;b++){
                for(c=b+1;c<a;c++){
                    for(d=c+1;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;
}

原文地址:http://blog.51cto.com/13688928/2119217

时间: 2024-11-26 02:55:54

hdu 1334 Perfect Cubes的相关文章

杭电 HDU ACM 1334 Perfect Cubes

Perfect Cubes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2413    Accepted Submission(s): 1061 Problem Description For hundreds of years Fermat's Last Theorem, which stated simply that for

(HDU)1334 -- Perfect Cubes (完美立方)

题目链接:http://vjudge.net/problem/HDU-1334 暴力枚举,我不知道我的优化是不是暴力里面最简单的... 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <algorithm> 6 #include <string> 7 #include <cstdlib>

poj 1543 Perfect Cubes (暴搜)

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

poj 1543 &amp; HDU 1334 &amp; ZOJ 1331 Perfect Cubes(数学 暴力大法好)

题目链接:http://poj.org/problem?id=1543 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 believ

hdu 3524 Perfect Squares 推公式求逆元

Perfect Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 501    Accepted Submission(s): 272 Problem Description A number x is called a perfect square if there exists an integer b satisfy

POJ 1543 Perfect Cubes

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14344   Accepted: 7524 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 remain

HDU1334_Perfect Cubes【水题】

Perfect Cubes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2192    Accepted Submission(s): 957 Problem Description For hundreds of years Fermat's Last Theorem, which stated simply that for n

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

zoj题目分类

饮水思源---zoj 转载自:http://bbs.sjtu.edu.cn/bbscon,board,ACMICPC,file,M.1084159773.A.html 注:所有不是太难的题都被归成了“简单题”,等到发现的时候已经太晚了,我太死脑筋 了……:( 有些题的程序我找不到了,555……:( SRbGa的题虽然都很经典……但是由于其中的大部分都是我看了oibh上的解题报告后做 的,所以就不写了…… 题目排列顺序没有规律……:( 按照个人感觉,最短路有的算做了DP,有的算做了图论. 有些比较