Problem 261

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Problem 261

Post by zwuupeape »

Apparently someone has already managed to solve it but for some reason I get wrong answer even though I am 100 % confident about the solution.

For 10^8 I get: 242816464261
For 10^13 I get: 7482405209124158762

Perhaps my fault is with the word 'distinct' ? What is meant by distinct? For some k, there may be more than one pair of (m,n) such that (k-m)^2 + ... k^2 = (n+1)^2 + ... (n+m)^2, so there is only need to count those values of k once - right?

Thanks.
User avatar
stijn263
Posts: 1505
Joined: Sat Sep 15, 2007 11:57 pm
Location: Netherlands

Re: Problem 261

Post by stijn263 »

For some k, there may be more than one pair of (m,n) such that (k-m)^2 + ... k^2 = (n+1)^2 + ... (n+m)^2, so there is only need to count those values of k once - right?
Exactly. Your result for 108 is slightly off. I didn't check the other one. Good luck!

Problem 261 (View Problem)
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 261

Post by daniel.is.fischer »

'distinct' == 'different', so you've interpreted that correctly.
However, your values are wrong. For 108, it's 243xxxxxxxxx, for 1013: 74828xxxxxxxxxxxxxx.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
Robert_Gerbicz
Posts: 26
Joined: Sat Oct 13, 2007 2:44 pm

Re: Problem 261

Post by Robert_Gerbicz »

That is very interesting. My code gives the same number for n=10^8 (still no answer for n=10^10, my code is a little slow, it would take about 2 days for one core):

is it also bad:
// f(999)=8347
// f(9999)=276416
// f(99999)=8340384
// f(999999)=253131726
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 261

Post by zwuupeape »

I get exactly that, too.
Robert_Gerbicz
Posts: 26
Joined: Sat Oct 13, 2007 2:44 pm

Re: Problem 261

Post by Robert_Gerbicz »

I found a bug, my new guess: f(10^6)=255978835
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 261

Post by daniel.is.fischer »

Robert_Gerbicz wrote:I found a bug, my new guess: f(10^6)=255978835
Yup.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 261

Post by zwuupeape »

I now tried a completely different approach. Scales much, much worse than the other but apparently finds some that the other misses - I cannot, for the life of mine, understand why. And it still doesn't match f(10^6) ...

Who can confirm 8446625 for 10^5?
277236 for 10^4 ?
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 261

Post by daniel.is.fischer »

zwuupeape wrote:I now tried a completely different approach. Scales much, much worse than the other but apparently finds some that the other misses - I cannot, for the life of mine, understand why. And it still doesn't match f(10^6) ...

Who can confirm 8446625 for 10^5?
Not I. You're still missing some.
277236 for 10^4 ?
That, yes.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
Rodinio
Posts: 5
Joined: Sat Oct 24, 2009 10:08 pm

Re: Problem 261

Post by Rodinio »

OK,

first post...

I really like this problem, and am sure to finish it quickly if it were not for the special special cases that I keep finding.
Can anyone confirm 10^8 as 243xxx202099 ? First three digits are ok thanks to a previous post, I get 10^6 just fine, and the runtime for this case is well under a minute in python, so I do believe I must be on to something. But I still get the red cross, so there must be another (probably stupid) bug... :?

(I'm perhaps obfuscating too much here, don't want to get on the wrong side of the etiquette here...)

Cheers
Rodinio
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 261

Post by daniel.is.fischer »

No, the sum for 108 ends in 7.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
MrDrake
Posts: 8
Joined: Fri Oct 16, 2009 2:44 am

Re: Problem 261

Post by MrDrake »

This is really annoying... I have an algorithm that will solve it but would take too long, and I can't see how to really re-work it. 10^6 is taking a minute to get the correct answer (as opposed to a few seconds for the wrong one).
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Problem 261

Post by quilan »

Finally got my missing part written so that my algorithm can work!

But curses, my algorithm runs in <1 second for 105, but I'm just shy of the correct amount (my result was juuuust lower than zwuupeape's result)... and brute force takes way too long. Time for a very lengthy debug time. *grumble*
ex ~100%'er... until the gf came along.
Image
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 261

Post by zwuupeape »

My incorrect algorithm is approximately O(sqrt(n)) time, I think. Well below one minute for 10^13 in unoptimized Python. Wonder how different that could be from everyone else's. Anyway, I hate that problem because I felt my 100% was near and it now seems further than ever :(
quintana
Posts: 11
Joined: Wed Jan 28, 2009 5:53 pm

Re: Problem 261

Post by quintana »

finally! 10^6 in 15ms. beyond that c++ is helpless, due to overflow. back to java...
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Problem 261

Post by quilan »

If it makes you feel any better, my 'O(sqrt(n))' algorithm took 3h42m to calculate in Python. Massively inefficient. It turns out there are a few odd side-cases one wouldn't normally expect (as everyone here seems to have noticed with their values being slightly low).
ex ~100%'er... until the gf came along.
Image
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 261

Post by zwuupeape »

Got it !! :)

Tricky and hard. A possible candidate, I think, for the hardest problem ever on PE, at least judging by the number of solvers so far ..
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Problem 261

Post by quilan »

zwuupeape wrote:Got it !! :)

Tricky and hard. A possible candidate, I think, for the hardest problem ever on PE, at least judging by the number of solvers so far ..
I'm pretty sure 245 had lower by around this length... but it's pretty close.
ex ~100%'er... until the gf came along.
Image
Rodinio
Posts: 5
Joined: Sat Oct 24, 2009 10:08 pm

Re: Problem 261

Post by Rodinio »

OK, I found one more (sparse) class of solutions so one more try:

Can someone confirm 10^7 -> 7835865568 ?
I'm stuck until I find a pattern to those special cases. :?

PS: I would really not mind seeing a correct solution for 10^8 either, Iknow I'm off (243296863635), but probably only one short... which would open the door to the next special case, I reckon.

Cheers
Rodinio
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 261

Post by daniel.is.fischer »

Both numbers are too low.
Il faut respecter la montagne -- c'est pourquoi les gypa&egrave;tes sont l&agrave;.
Post Reply