POJ 1543 && HDU 1334 Perfect Cubes(水~)

Description
给一个数N,表示a<=N,求出所有满足a^3=b^3+c^3+d^3的解
Input
一个整数N,N<=100
Output
求出所有满足a^3=b^3+c^3+d^3的解,用“Cube = a, Triple = (b,c,d)”的格式写出。输出不重复的解,并按从小到大的顺序
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)
Solution
水题,暴搜一边即可
Code

#include<stdio.h>
#define X(x) x*x*x
int main()
{
    int n,i,j,k,l;
    scanf("%d",&n);
    for(l=6;l<=n;l++)
    {
        for(i=2;i<l;i++)
            for(j=i;j<l;j++)
                for(k=j;k<l;k++)
                    if(X(l)-X(i)-X(j)-X(k)==0)
                        printf("Cube = %d, Triple = (%d,%d,%d)\n",l,i,j,k);
    }
}

你可能感兴趣的:(POJ 1543 && HDU 1334 Perfect Cubes(水~))