Uva 386 - Perfect Cubes

/*

Solving Method: Use simple Brute force system.

Look, Time 2 sec and your complexity will be 196(200-4) * 198(200-2) * 197(200-3) * 196(200-4) which is less than 10^12 for 2 sec Time limit :)

*/

#include<bits/stdc++.h>
#define N 50000
#define sf scanf
#define pf printf
using namespace std;

typedef long long LL;

void solution()
{
    LL i,j,k,l,a,b,c,d,sum;

    for(i=6; i<=200; i++)
    {
        a = i*i*i;

        for(j=2; j<=200; j++)
        {
            b = j*j*j;

            for(k = j+1; k<=200; k++)
            {
                c = k*k*k;

                for(l=k+1; l<=200; l++)
                {
                    d = l*l*l;

                    sum = b+c+d;

                    if(sum == a)
                    {
                        pf("Cube = %lld, Triple = (%lld,%lld,%lld)\n",i,j,k,l);
                    }
                }
            }
        }
    }
}

int main()
{
    solution();

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number