
-----------------------------------
Martin
Sun May 21, 2006 9:18 pm

Project Euler
-----------------------------------
http://www.mathschallenge.net/index.php?section=project

Fun and pretty straightforward programming contest. Check it out.

-----------------------------------
Cervantes
Sun May 21, 2006 9:34 pm


-----------------------------------
With credit for the link going to bugzpodder, of course. ;)

-----------------------------------
Martin
Sun May 21, 2006 9:51 pm


-----------------------------------
I should start reading the contests forum I think ;)

I found it through some Ruby site while looking for stuff on Ruby coding style. Anyway, locked.

-----------------------------------
zylum
Wed May 24, 2006 7:27 pm


-----------------------------------
why did you lock it? the thread bugz posted the link in was about something else...

anyway, how many problems have you solved? lets discuss some of the problems here  :wink: 

i have done problems 1-11,13,16 and 20..

-----------------------------------
Martin
Wed May 24, 2006 11:03 pm


-----------------------------------
Yeah, I locked it before I looked up bugz's post, then forgot about it :p

So far I've done

1-25, 28, 37, 40, 42, 48 and 79.

EDIT: [url=http://www.mathschallenge.net/index.php?section=project&ref=scores&profile=4546]Here's my profile.

-----------------------------------
zylum
Thu May 25, 2006 5:31 pm


-----------------------------------
now i did 1-25 (except 19) and 67... can someone just tell me the answer to 19? that question is annoying  :?

-----------------------------------
Martin
Thu May 25, 2006 6:23 pm


-----------------------------------
19 is really easy.

The Jan 1 1901 is a Monday. January has 31 days. What day of the week will it be 31 days after a Monday? nextday = (today + 31) mod 7.

After that, February has 28 days (because it's not a leap year). So nextday = (today +  28) mod 7.

And so on.

-----------------------------------
zylum
Thu May 25, 2006 11:29 pm


-----------------------------------
yeah, easy but tedious... my least favourite one thus far was the one where you had to count how many letters it would take to spell out all the numbers from one to one thousand  :?  easy but tedious..

btw, jan 1st, 1900 was no necessarily a monday, it says jan 1900.. unless you have found this out then... actually according to http://www.timeanddate.com/calendar/index.html?year=1901&country=1 jan 1, 1901 is a Tuesday  :wink:

[edit] yay i got it  8-) [/edit]

-----------------------------------
Bobrobyn
Fri May 26, 2006 7:32 am


-----------------------------------
yeah, easy but tedious... my least favourite one thus far was the one where you had to count how many letters it would take to spell out all the numbers from one to one thousand  :?  easy but tedious..

btw, jan 1st, 1900 was no necessarily a monday, it says jan 1900.. unless you have found this out then... actually according to http://www.timeanddate.com/calendar/index.html?year=1901&country=1 jan 1, 1901 is a Tuesday  :wink:



If you enjoy solving the problems, it really isn't tedious.

Anyways, thanks for the link.  I'll try it sometime -- probably after exams.

-----------------------------------
zylum
Fri May 26, 2006 12:56 pm


-----------------------------------
hmm.. i just realized something... in my program i didnt check for leap years and i still got the correct answer  :lol:

-----------------------------------
zylum
Mon May 29, 2006 12:06 am


-----------------------------------
528 points, 44 problems solved  :lol: 

solved all problems of difficulty < 16 except for 45... cant seem to get that one to work.. any ideas?

-----------------------------------
Martin
Mon May 29, 2006 2:04 am


-----------------------------------
528 points, 44 problems solved  :lol: 

Oh it's on Zylum.

-----------------------------------
zylum
Mon May 29, 2006 7:10 pm


-----------------------------------
528 points, 44 problems solved  :lol: 

Oh it's on Zylum.

oh is it?

http://mathschallenge.net/index.php?section=project&ref=scores&profile=4547

-----------------------------------
bugzpodder
Fri Jun 09, 2006 8:49 am


-----------------------------------
wow u guys are fast.  i probably dont even as many solved as martin does (about the same)

-----------------------------------
bugzpodder
Sat Jun 10, 2006 10:08 am


-----------------------------------
really do you guys do this 12 hours a day?  now you guys are like 700 points, way ahead of me :)

-----------------------------------
Null
Sat Jun 10, 2006 10:46 am


-----------------------------------
With grade 10 (enriched) math, I've solved:

1-8, 13, 16, 20, 22, 25, and 48.

(mostly using Ruby, but with a bit of C++ when there was heavy number crunching). 

For a few of the problems that I haven't solved, the program would theoretically work, but takes too long to calculate.

-----------------------------------
Martin
Sun Jun 11, 2006 7:08 pm


-----------------------------------
really do you guys do this 12 hours a day?  now you guys are like 700 points, way ahead of me :)

Nah, first bunch I did in a 3 or so hour stretch, lately I've been trying to do one question every couple of days. I'm kind of stuck though - there are a few more that I'll be able to get, but after that I don't even know where to begin.

-----------------------------------
cool dude
Sun Jun 11, 2006 8:58 pm


-----------------------------------
i just started solving some of them and problem 2 is bugging me! i am pretty sure the answer is: 24196302. although it says its incorrect. the question was:


Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even terms in the sequence below one million.



i used java to try and solve this question and this is wat i have which theoretically is correct from wat i understood from the instructions.


public class problem2 {
	public static void main(String[] args) {
		int total = 2;
		int[] num = new int[1000000];
		
		for(int i = 1; i < 1000000; i++){
			if(i == 1){
				num[1] = 1;
			}
			if(i == 2) {
				num[2] = 2;
			}
			else if(i > 2){
				num[i] = num[i - 2] + num[i - 1];
				if (num[i] % 2 == 0){
					total = total + num[i];
				}
			}
		}
		System.out.println(total);
	}
}

-----------------------------------
wtd
Sun Jun 11, 2006 10:47 pm


-----------------------------------
Does your code account for "num[i]" being equal to 2?

-----------------------------------
zylum
Mon Jun 12, 2006 12:04 am


-----------------------------------
all terms below one million. not the first one million terms.  :wink: 

i dont do this anymore that often. i probably spent about 10 hours in total on all of these. as martin said, the first bunch dont take too long. for the sudoku one i just used a program that i already made (which is posted somewhere on this site).

-----------------------------------
bugzpodder
Mon Jun 12, 2006 8:49 am


-----------------------------------
really do you guys do this 12 hours a day?  now you guys are like 700 points, way ahead of me :)

Nah, first bunch I did in a 3 or so hour stretch, lately I've been trying to do one question every couple of days. I'm kind of stuck though - there are a few more that I'll be able to get, but after that I don't even know where to begin.

How come you are stuck??  is it because it is hard to make efficient code?

-----------------------------------
cool dude
Mon Jun 12, 2006 4:51 pm


-----------------------------------
[quote="zylum"]all terms below one million. not the first one million terms.  :wink: 
quote]

Thanks zylum. i hate play on word puzzles. no wonder i did bad in english lol.

-----------------------------------
Martin
Mon Jun 12, 2006 8:59 pm


-----------------------------------
really do you guys do this 12 hours a day?  now you guys are like 700 points, way ahead of me :)

Nah, first bunch I did in a 3 or so hour stretch, lately I've been trying to do one question every couple of days. I'm kind of stuck though - there are a few more that I'll be able to get, but after that I don't even know where to begin.

How come you are stuck??  is it because it is hard to make efficient code?

For some of them. The big problem though is that I don't know the algorithms to actually do what I want to (like, even if everything would execute instantly I wouldn't know where to start). Right now I'm trying to figure out the recurring decimal problems, they're kind of tricky. Slowly hacking through Introduction to Algorithms too. I'll figure it out eventually.

-----------------------------------
zylum
Tue Jun 13, 2006 8:36 am


-----------------------------------
the decimal problem involves primes.. not just any primes. they form a sequence. find the largest prime in that sequence such that it is less than 1000.. there, you dont even need a program  :wink: 

i find that a lot of these problems involve some sort of math related trivia. you need some sort of formula or something otherwise it wont execute fast enough. i usually do a quick search in google before i write any code. also search mathworld.wolfram.com and the online sequence encyclopedia

-----------------------------------
cool dude
Tue Jun 13, 2006 7:35 pm


-----------------------------------
how did u do problem 20. i'm getting a really really large number and i did the problem correctly (or at least how i understood it). i prolly misunderstood it like the other one so any hints?

-----------------------------------
Martin
Tue Jun 13, 2006 8:48 pm


-----------------------------------
It's about as straightforward as they come.

Compute 100!

Find the sum of the digits.

-----------------------------------
cool dude
Tue Jun 13, 2006 10:06 pm


-----------------------------------
i might be wrong but try punching that in  on your calculator the number is so big that it gives u an error and if u were to add up all the numbers up it would be even bigger. 


public class Problem20 {
	public static void main (String[] args){
		int n = 100;
		int total = 100;
		int sum = 0;
		
		for (int i = 1; i  n2. That would give you a sequence of squares where the maximum is, say, 6^2 and the minimum is, say, 25^2. Your s2-s1 will be negative.

Second, you should break out of those for loops if your conditional (s2 - s1 == i) is true.

I spent some time today on this problem. Instead of ranging 'n' in a for loop and checking if it works, I developed an equation to predict what n should be, given a value for n2. It essentially amounts to solving the cubic:
2x^3 + 3x^2 + x - diff*6 = 0
where diff is the difference between the palindromic number and the sum of squares from 1 to n2.

It worked beautifully, until the numbers started to get so large that my algorithm to solve the cubic (Cardano's method) produced Infinity as the solution. Perhaps I should switch to Newton's Method.

-----------------------------------
cool dude
Wed Aug 23, 2006 6:00 pm


-----------------------------------
how would i break out of my for loop? also wat should i go up to in my for loop if not 1000?

-----------------------------------
Cervantes
Wed Aug 23, 2006 6:59 pm


-----------------------------------
These are not difficult questions...

The easiest way to break out of the loops is to factor them out into a function. You can return from the function at any time.

The second for loop should go up to `n2 - 1'

-----------------------------------
Cervantes
Sun Aug 27, 2006 4:37 pm


-----------------------------------
Ouch, zylum's taking a beating. ;)

http://www.compsci.ca/v2/download.php?id=4389

-----------------------------------
the_short1
Mon Aug 28, 2006 6:40 pm


-----------------------------------
i think what you mean cool dude .. . is this? 

[url=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/branch.html]Branching Statements
In your case... its the "break" statement... Hope that helps, found it a few months ago... sadly our teacher in gr12 compsci didnt even teach us about "Break". . only "return"  1000000000 then    %because 10 digits is the maximum that Turing can handle!
            realsum += sum - 1000000000 %only goes to 8 decimal places, so we can add all of these up
            RealSum += 1            %since we're subtracting 10 ** 9 each time, add 1 to the 10 ** 9 total
            sum := 0                %restart the sum
        end if
    end if
end for
put RealSum, " times 10 to the nine, ", realsum - 1 %because 1 is not a prime, but was included
So, I tried 370 015 402 174 (with no spaces). I also tried 37 015 402 174, 37 015 402 175, and 370 015 402 175. What's going on here???

-----------------------------------
neufelni
Fri Sep 01, 2006 1:13 pm


-----------------------------------
I'm working on problem 17 now and I am stuck. First I used pencil and paper and made a list of all the basic words used like one, two, twenty, hundred .... I figured out how many times they appeared in the range of 1-1000 and multiplied it by the number of letters in each word, and added them all together, but that didn't give me the right answer. So I typed every number between 1-1000 with a word processor and did a character count, but that didn't give me the right answer neither. I have no idea how I would make a program to solve this, so please help me. Here's the list of numbers I made with Word. I checked through it to see if I made any spelling mistakes or anything like that but I didn't find anything.

-----------------------------------
cool dude
Fri Sep 01, 2006 1:52 pm


-----------------------------------
wow u actually sat there typing out all the numbers when it would take u so little time to make a program lol. i don't feel like checking all the numbers to check for spelling mistakes. to make a program u would use arrays which would be really really easy. 

P.S. u are close with the character count. u must have missed one number. i don't think u made a spelling mistake. check if u didn't miss a number  :wink:

-----------------------------------
neufelni
Fri Sep 01, 2006 2:08 pm


-----------------------------------
wow u actually sat there typing out all the numbers when it would take u so little time to make a program lol. i don't feel like checking all the numbers to check for spelling mistakes. to make a program u would use arrays which would be really really easy. 

P.S. u are close with the character count. u must have missed one number. i don't think u made a spelling mistake. check if u didn't miss a number  :wink:
I didn't type it all out, I did alot of copying and pasting.
And I did not miss a number, the word count says I have exactly 1000 words.
EDIT: I just found one spelling mistake but it's still not right, there must be more.

-----------------------------------
the_short1
Fri Sep 01, 2006 2:08 pm


-----------------------------------

boolean pally = true;    // flag set to false if not a pallindrome 
String temp = "";         // Holds number in string form
int i = 1331;                // the number your testing (would be for loop)

temp = ""+i; // pass the current number into string
for (int c = 0; c  054
    for (int d = 0; d < temp.length(); d ++){
	flip = flip + temp.substring(temp.length()-1-d,temp.length()-0-d);
    }
    num1 = Long.parseLong(temp+flip);
    
    // and for odd pallys ( check both on same for loop itteration )
    num2 = Long.parseLong(temp+flip.substring(1); // Chop off 1 digit from flip (eg: 450 + _54 -> 45054 instead of 450054)
}


And nick... if you know java.. i would suggest using Java's BigInteger and its "num.isProbablePrime(5);" function.. where num is a BigInteger that you want to test.... . it works adequately when primes start getting bigger.. .but  one of the most efficient is the "Sieve of Eratosthenes".. google it

-----------------------------------
Cervantes
Fri Sep 01, 2006 4:27 pm


-----------------------------------
Let's say n1 and n2 are 0 or natural numbers. We're interested in the sum of the squares of all whole numbers between n1+1 and n2.

So if n1 is 5 and n2 is 8, we're interested in 6^2 + 7^2 + 8^2.

That value can be calculated by summing the squares of the natural numbers from 1 to n2 then subtracting the sum of the squares of the natural numbers from 1 to n1. Like this:
(n2(n2+1)(2*n2+1) - n1(n1+1)(2*n1+1)) / 6

Now, we're interested in determining whether a number, such as 595, can be written as the sum of the squares of consecutive natural numbers. We might pick a value for n2 and pick another value for n1 and use the formula to see if we get 595 or not. If we generate all possible combinations of n2 and n1 such that n1 < n2 and n2 < floor(sqrt(595 / 2)), we can perform a check.

But it's slow. Too many iterations.

We can remove an entire loop. Replace it with some math. Once we've picked a value for n2, we don't need to iterate over values of n1. Using math, we can calculate what n1 must be in order to get our sum to equal 595. Quite often the solution will state that n1 must be something like 5.7 or some other real number. That would be telling you that 5.7^2 + 6.7^2 ... = 595. But we're only interested in natural numbers, so we disregard that, increase n2, then check n1 again.

I'll tell you right now that this method requires you to be able to solve a cubic equation. Even if you can do that, it's a bit slow. In a fast language the program would probably run in time, but in Ruby, mine didn't. I found another way quite similar to this that only required me to solve a quadratic. This is much faster.

-----------------------------------
neufelni
Fri Sep 01, 2006 4:27 pm


-----------------------------------

And nick... if you know java.. i would suggest using Java's BigInteger and its "num.isProbablePrime(5);" function.. where num is a BigInteger that you want to test.... . it works fastest when primes start getting bigger.. .but  one of the most efficient is the "Sieve of Eratosthenes"
I don't know Java all that well, I just know the basics. I probably know enough to solve most of these problems, but not very fast and efficiently.
I am best with Turing and also know a bit of C++ and Python.
I tried using BigInteger for Problem 16, What is the sum of the digits of 2**1000, but I couldn't figure out how to use it. So I used Python and it gave me the answer without having to using anything special.

-----------------------------------
the_short1
Fri Sep 01, 2006 5:32 pm


-----------------------------------
@Cervantes.. are you in uni now? i suck at deriving formulas from scratch.. .. lol.. . the equation narrows down to this if my math serves me today..?
(2*n2^3 + 3*n2^2 + n2) - (2*n1^3 + 3*n1^2 + n1) = num * 6

@Nick: Python.. thats something im curious to learn :)... i have a BigInteger tutorial in the java tut section if your willing to learn it..
String digits = (new BigInteger("2").pow(1000)).toString();
the string digits now contains the massive result, whose digits can be counted simply with a for loop and substrings, and Integer.parseInt

-----------------------------------
wtd
Fri Sep 01, 2006 5:42 pm


-----------------------------------
the_short1, just for demo purposes, that piece of Java code can be rwritten in Python as:

digits = str(2 ** 1000)

Perhaps that's a bit more incentive to learn a new language.  :)

-----------------------------------
Cervantes
Fri Sep 01, 2006 7:17 pm


-----------------------------------
@Cervantes.. are you in uni now?
I'm in limbo. I move in Sunday. :dance:

i suck at deriving formulas from scratch.. .. lol.. . the equation narrows down to this if my math serves me today..?
(2*n2^3 + 3*n2^2 + n2) - (2*n1^3 + 3*n1^2 + n1) = num * 6

That looks familiar. Now, set that up in the form of a quadratic for n1 (a*n1^3 + b*n1^2 + c*n1 + d = 0). n2 is constant (we iterate through values of n2, but at this time we treat it as a constant), so the n2 values and the num*6 will together comprise `d'. 

Now to solve, you've got a few options. The one I like is [url=http://en.wikipedia.org/wiki/Cubic_equation#Cardano.27s_method]Cardano's method. It's fast; almost as fast as solving a quadratic. But the problem with it is that when the root gets extreme, it gives trouble to a computer. As I recall, you had a number divided by a really tiny (close to zero) number, then multipled by another really small number, giving you a decent sized number. But as soon as you do the first division, the number is too big to fit in memory.  Or something like that.

So your other alternative is to use [url=http://en.wikipedia.org/wiki/Newton's_method]Newton's Method. This will work, but it is slow because it is iterative. It's only an approximation of the roots.
[/quote]

-----------------------------------
the_short1
Fri Sep 01, 2006 9:03 pm


-----------------------------------
indeed... i read a bit of other python code on project euler forums and i liked what i read but for robotics .. . it would be better to focus on learning better C skills / c++....

but .. ide just like to mention.. i got around to implementing a sieve... and im totally impressed... .  first 10 million primes into an array.. in 3seconds.. amazing and ide avise any other prime seekers to follow same route..

@ Cervantes.. hmm... well both methods dont sound too great.  As page file memory sucks the speed out of things.. . and aproximations and slowness doesnt sound good either.... hmm well im off to work... ill try the cubic tomorow using the first method. thanks

-----------------------------------
Cervantes
Fri Sep 01, 2006 9:30 pm


-----------------------------------
Don't worry too much about approximations. If you get an answer of 5.00027193 then you can bet that you've got an integer solution. If you like, you could then check the equation using 5.0.

What's this about "page file memory"?

-----------------------------------
cool dude
Sat Sep 02, 2006 12:22 pm


-----------------------------------
how would i determine if the number is a decimal or not?

-----------------------------------
Clayton
Sat Sep 02, 2006 1:19 pm


-----------------------------------
round the number down and divide the non-rounded number by the rounded one and see if theres a remainder?


real num = 5.5
int num2 = round_down (num)
put remainder (num/num2)


something like that?

-----------------------------------
neufelni
Sat Sep 02, 2006 1:51 pm


-----------------------------------
Can anyone give me some tips for making programs run faster. All of the programs I make run really slow.

-----------------------------------
zylum
Sat Sep 02, 2006 2:47 pm


-----------------------------------
choose a better algorithm. some require the answer to meet multiple criteria.  to meet these criteria you probably use nested loops. the outter loops should be for the coarsest criteria, therefore there are fewer inner loops. also look for ways to reduce the amount of loops you need to do and criteria you have to meet. some criteria might overlap.

-----------------------------------
neufelni
Sat Sep 02, 2006 3:17 pm


-----------------------------------
Here is my code in Python for Problem 3, what is the largest prime factor of 317584931803. largestPrime = 0
num = 317584931803
while num > 2:
	num -= 2
	i = 2
	if 317584931803 % num == 0:
		while i < num:
			if num % i == 0:
				break
			
			if i == num - 1:
				largestPrime = num
				
			i += 1
	print num
	if largestPrime != 0:
		break		
			
print "The largest prime is: ", largestPrime
First I check if each number is divisible by 317584931803, then if it is I check to see if it is a prime number. I used Python because it handles big numbers better than Java or C++, I don't have to use something like BigInteger. I think this is the best way to have as few inner loops as possible. I already break out of the inner loop the moment I find out that it isn't a prime number, but it's still way too slow. How could I make this faster?

-----------------------------------
wtd
Sat Sep 02, 2006 3:36 pm


-----------------------------------
      while i < num:
         if num % i == 0:
            break
         
         if i == num - 1:
            largestPrime = num
            
         i += 1 

Since the first thing to run in your loop is a conditional break, how about...

      while i < num and num % i != 0:
         if i == num - 1:
            largestPrime = num
            
         i += 1 

-----------------------------------
Cervantes
Sat Sep 02, 2006 4:15 pm


-----------------------------------
There's no sense in starting that loop with num equal to that huge number. 

Instead of that huge number, let's say we're working the number 14. There's no sense in checking whether 13, 12, 11, 10, 9, or 8 are divisible by 14. The biggest number that could possibly be a factor of 14 is 14/2 = 7.

So it doesn't make much sense starting from the top and working down since the numbers are much less common. Rather, start from 2, and work up. 14 / 2 = 7, so check if 7 is prime. It is, but if it weren't, then you'd go to 14/3 = 4.67 and check if that is an integer and if it's prime, and so on.

Also, factor out that code that checks whether a number is prime. It's very useful to have in these problems, and it's just good coding practice to make a method out of something as fundamental as 'prime?'

-----------------------------------
neufelni
Sat Sep 02, 2006 6:27 pm


-----------------------------------
OK, I got the answer. I tried the method you suggested. It started out really fast but got progressively slower until it took about 2 seconds for num to decrease by 1. So I added an if statement so that it used your method while num > 200 000, and then it switched to my old method of decreasing num by  one each time.

-----------------------------------
the_short1
Sat Sep 02, 2006 9:55 pm


-----------------------------------
@ Cervantes: you said the number got too big to fit in memory, hence after that it would use page file memory instead ;)

@ Nick: Zylum hit the head on the nail... But ill add my $0.02.. less itterations, less comparisons, less complex math (avoid sqrt)... 

Another thing i try to do, is output the values known to be wrong to find hidden connections.... like, in one [url=http://www.mathschallenge.net/index.php?section=project&ref=problems&id=69]question 
it is quite ovious that prime numbers wont be the right ones, so i skip past them

-----------------------------------
Cervantes
Sat Sep 02, 2006 10:06 pm


-----------------------------------
@ Cervantes: you said the number got too big to fit in memory, hence after that it would use page file memory instead ;)


I'm pretty sure the number never actually got so big it couldn't be stored in all 512 of my megabytes of memory. But it did get too big for Ruby to deal with it, so it just labelled it as "NaN" for "Not a Number".

-----------------------------------
Andy
Tue Sep 05, 2006 3:25 pm


-----------------------------------
@ Cervantes: you said the number got too big to fit in memory, hence after that it would use page file memory instead ;)

based on that comment, i dont think you know much about the memory architecture... TLB makes physical and virtual memory into a big contiguous chunk

-----------------------------------
Cervantes
Tue Sep 05, 2006 5:00 pm


-----------------------------------
No, I don't. But I'm telling you, the number I was dealing with wouldn't have been greater than or equal to 2^((512 - memory used by OS) * 1024 * 1024 * 8).

-----------------------------------
Andy
Tue Sep 05, 2006 5:18 pm


-----------------------------------
oh minsc... the comment was directed towards the short

-----------------------------------
cool dude
Tue Sep 05, 2006 5:35 pm


-----------------------------------
k cerventes thanks for the suggestion. i tried it out and i don't know where i went wrong but it's not working and i get no error messages. 
basically i did wat u told me by subtracting s2 from i to figure out wat s1. then i had to check if s1 value is actually a value that is the sum of consecutive squares so in order to do so i had to solve a cubic equation as u told me. the equation is:

2x^3 + 3x^2 + x - s2 = 0

at first i didn't know how to solve it so i went to this site: 
import java.math.*;

public class Problem125 {
	public static void main (String[] args) {
		String ii = "";		//stores the string of the number
		String reversed;	//stores the reversed number
		int consecutive;	//stores the sum of the consecutive square numbers
		int sum = 0;		//stores the sum of all the palindroms - where the sum of consecutive square numbers adds up to the palindrom
		int cnt = 0;		//stores the number of consecutive integers to make sure its greater than one
		int s1 = 0;
		double s2;
		double a = 2;
		double b = 3;
		double c = 1;
		double f, g, h = 0;
		double r, s, t, iii, j, k, l, m, n, p, u = 0;
		double x1, x2, x3 = 0;
		double xx1, xx2, xx3 = 0;
		
		for (int i = 2; i < 100000000; i++) {	
			boolean correct = false;
			ii = Integer.toString(i);	//converts the number to a string to reverse it using substring
			reversed = "";
			
			//reverses the number to see if its a palindrom
            for (int jj=0; jj  0) {
                    	r = -1 * (g / 2) + Math.pow(h, (1/2));
                    	s = Math.pow (r, (1/3));
                    	t = -1 * (g / 2) - Math.pow(h, (1/2));
                    	u = Math.pow(t, (1/3));
                    	
                    	x1 = (s + u) - (b/3 * a);
                    	x2 = -1 * (s + u) / 2 - (b / 3 * a) + iii * (s - u) * Math.pow(3, (1/2)) / 2;
                    	x3 = -1 * (s + u) / 2 - (b / 3 * a) - iii * (s - u) * Math.pow(3, (1/2)) / 2;
                    	
                    	xx1 = Math.floor (x1);
                    	xx2 = Math.floor (x2);
                    	xx3 = Math.floor (x3);
                    	
                    	//if all roots (n's) are whole numbers than its consecutive and add them
                    	if (x1 / xx1 == 1 && x2 / xx2 == 1 && x3 / xx3 == 1) { 
	                    	System.out.println(i);
	                        sum = sum + i; 
	                    } 
                    }
                    
                    //all 3 roots real
                    if (h 