Problem 42935. Sums of cubes and squares of sums
Solution Stats
Problem Comments

2 Comments
I did not originally look to see exactly how far one could go. It looks like, IF one is careful in the important expression, you should be able to get to 3329020. I'd expect that the code I'd write that would solve this to go as far as 3329020 would employ an initial test to know if n is even or odd, changing the expression I'd write depending on the parity of n. Of course that branch would also increase the complexity, so raising the Cody score.
Can someone point me in the right direction?
n = 1e5;
y_correct = uint64(500010000050000);
I get 500010000050005. I do not know how to go beyond double precision.
function y = cubesLessSquare(n)
% Formula
N = (((sum((1:n).^3)*2  sum(1:n)^2)*2/n))
% double to char
C = sprintf('%f',N)
% char to vector
Y = C  '0'
% take out the dot and the numbers after the dot
Dot = find(Y<0)
Y([Dot:end]) = []
% join the the numbers
Z = sprintf('%d',Y)
% make to double
y = str2num(Z)
end
Solution Comments

1 Comment
This appears to be true only for sequences of numbers starting from 1 and some combinations of these sequences.

1 Comment
unbelievable!get it

2 Comments
it is exactly the right way to solve this one.
Could you please explain a bit about how the problem was converted to a polynomial function?

1 Comment
works for n up to 3329020

1 Comment
works for n up to 2642245, so it doesn't use the full potential of the uint64

1 Comment
isequal ignores the data type of the values in determining whether they are equal.
isequal(uint64(15503197751395200),15503197751395199,15503197751395201,15503197751395200)
flintmax('double') = 2^53 < 15503197751395200
eps(15503197751395200) = 2

1 Comment
Big letters, small letters and a bit of luck.
Problem Recent Solvers180
Suggested Problems

Determine if a Given Number is a Triangle Number
348 Solvers

303 Solvers

579 Solvers

440 Solvers

426 Solvers
More from this Author4
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!