In this HackerEarth Little Jhol and Brute Force problem solution, Little Syed loves brute force. He thinks that brute force can be the solution to any problem in the world. You give him any question, and he'll have a brute force answer ready for you, almost all the time. His good friend Little Jhool (Like, always!) decides to teach him a lesson, by giving him problems that cannot be solved by brute force, because he wants Syed to learn algorithms.

Given a number, n, Syed needs to find the number closest to n, though less than n which satisfies Jhool's swinging theorem.
Jhool's swinging Theorem: A number n, such that it can be expressed as a sum of two positive algebraic cubes; AND, if that number can be expressed in such a manner in more than one way - it satisfies the theorem.

Now, everyone here on HackerEarth knows how much we hate Little Jhool (No, not really!) - so we want you to help Syed in figuring out Jhool's queries - once and for all!

HackerEarth Little Jhool and Brute Force problem solution

HackerEarth Little Jhool and Brute Force problem solution.

l = [1729,4104,13832,20683,32832,39312,40033,46683,64232,65728,110656,110808,134379,149389,165464,171288,195841,216027,216125,262656,314496,320264,327763,373464,402597,439101,443889,513000,513856,515375,525824,558441,593047,684019,704977]
#print len(l)
tc = int(raw_input())
while (tc>0):
  tc = tc - 1
  n = int(raw_input())
  if n<=1729:
      print "-1"
  for i in xrange(len(l)):
    if l[i]>=n:
      print l[i-1]

Second solution

#include <cstdlib>
#include <stdio.h>
#include <cstring>
#include <complex>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iomanip>
#include <utility>
#include <locale>
#include <sstream>
#include <string>
#define FOR(i,n) for(i=0;i<n;i++)
#define FORI(i,a,n) for(i=a;i<=n;i++)
#define FORC(it,C) for(it=C.begin();it!=C.end();it++)
#define scanI(x) scanf("%d",&x)
#define scanD(x) scanf("%lf",&x)
#define print(x) printf("%d\n",x)
#define mod 10000
#define ll unsigned long long
#define max 100000000
#define sq(x) (x*x)
#define MAX 1000000
#define  S sqrt(MAX)
#define rP(n) (sieve[n>>6]|=(1<<((n>>1)&31))) 
#define gP(n) sieve[n>>6]&(1<<((n>>1)&31))
#define ct_prime 78498 
typedef long long int lint;

using namespace std;

int A[36]={1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464,
 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597, 439101, 443889, 513000, 513856, 515375, 
 525824, 558441, 593047, 684019, 704977,805688 };

int main()
  int t;
  int key;
    ll n;
    int* p =lower_bound(A,A+36,n);
  return 0;