-4
A perfect square is a number that is the square of an integer.
However, let's define something called a Magical Square, which is a perfect square with the following restriction:
The perfect square must be the sum of the numbers 1...N for some natural number N. Write a program that calculates the first X magical squares:
The first magical square is 1 (not 0, since N >= 1). The values of X are: 1 <= X <= 15. The program should be efficient and your score is the time taken to calculate the magical squares in seconds. The winner is the program that runs in the least amount of time. Please also include the generated numbers.
You can't hard-code the values, or read them from a file, etc. They MUST be calculated by the program.
Some examples: 1, 36, 1225, ...
1>
4So isn't this just numbers that are perfect squares AND triangular numbers? – mdc32 – 2014-11-23T02:56:38.873
@mdc32, yes it is. – mmk – 2014-11-23T02:58:38.870
So, essentially, if sqrt(x*(x-1)) is a whole number, then print it. – mdc32 – 2014-11-23T03:11:10.483
"The winner is the program that runs in the least amount of time." As measured on which machine? Unless they're all measured on the same machine (which usually means yours) this is not an objective winning criterion. – Martin Ender – 2014-11-23T10:18:47.983
@MartinBüttner, I'll time it on my machine as well. – mmk – 2014-11-23T14:26:02.153
Are we allowed to use floating point numbers? – TheNumberOne – 2014-11-23T16:42:47.197