Problem 002

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.
newinkles
Posts: 1
Joined: Sun Mar 02, 2008 8:57 pm

Problem 002

Post by newinkles » Sun Mar 02, 2008 9:02 pm

In the problem it says the sum of the even valued terms that do not exceed 4million. But the answer is the first term over 4 million. This might need to be reworded.

Nathan

User avatar
hk
Administrator
Posts: 10403
Joined: Sun Mar 26, 2006 9:34 am
Location: Haren, Netherlands

Re: Problem 2

Post by hk » Sun Mar 02, 2008 9:52 pm

Why should the sum of the even valued fibonacci numbers less than 4 million not exceed 4 million?
The first fibonacci number that exceeds four million is 5702887. And that's not the correct answer.

So the individual terms to add must be less than 4 million, the sum does not need to be.
Image

User avatar
kinyel
Posts: 4
Joined: Thu Apr 10, 2008 6:05 pm

problem 2 help please translate or example ...

Post by kinyel » Thu Apr 10, 2008 6:20 pm

Hello
I'm french (nobody's perfect... ;) ) and my english is bad ...
and I don't understand really
"Find the sum of all the even-valued terms in the sequence which do not exceed four million."
what is "even valued" ? why not only "all terms" ?
please can someone translate in french, or (better ?) give me the wanted sum for the first 10 terms for example ...
( 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 )
I can't solve this problem even if I've solve 20 others problems yet
:?
thanks for help !

User avatar
hk
Administrator
Posts: 10403
Joined: Sun Mar 26, 2006 9:34 am
Location: Haren, Netherlands

Re: problem 2 help please translate or example ...

Post by hk » Thu Apr 10, 2008 6:26 pm

even numbers are numbers divisible by 2.
So you are asked to sum the Fibonacci numbers less than 4 million that are divisible by 2.
Image

User avatar
kinyel
Posts: 4
Joined: Thu Apr 10, 2008 6:05 pm

Re: problem 2 help please translate or example ...

Post by kinyel » Thu Apr 10, 2008 6:38 pm

thank you very, very much !
:D
(never I think this and automatic translate don't give this ...)

dgiancaspro
Posts: 2
Joined: Sat Oct 25, 2008 9:58 pm

Problem 2 -- What the heck ?

Post by dgiancaspro » Sat Oct 25, 2008 10:12 pm

Sorry in advance for the long post ....
I completely understand the problem as it is stated. I wrote a quick brute force ruby program ... here it is ...

[snip]

I can't see what I'm doing wrong ... a nudge ... or a brick to the head ... in the right direction would be appreciated.

Thanks
Dave
Last edited by daniel.is.fischer on Sat Oct 25, 2008 10:24 pm, edited 1 time in total.
Reason: Remove code and answer

User avatar
xan
Posts: 621
Joined: Fri Jul 27, 2007 11:43 pm
Location: North Carolina, USA
Contact:

Re: Problem 2 -- What the heck ?

Post by xan » Sat Oct 25, 2008 10:19 pm

I can verify that your answer is correct. Please edit your post to remove the answer and code to avoid spoiling it for anyone else.

I don't know why your answer wasn't accepted. Maybe a copy/paste brought in some extra characters. If the problem persists, maybe an admin can figure out what the problem is.

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

Re: Problem 2 -- What the heck ?

Post by daniel.is.fischer » Sat Oct 25, 2008 10:31 pm

Whether it was a copy/paste slip or a server glitch, please try again and if that doesn't work, notify us.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.

dgiancaspro
Posts: 2
Joined: Sat Oct 25, 2008 9:58 pm

Re: Problem 2 -- What the heck ?

Post by dgiancaspro » Sun Oct 26, 2008 12:10 am

Looks like it was a Copy/Paste glitch ... The one thing I didn't try was typing it in by hand. That's what I get for being lazy.
Sorry for the spoiler .... I'll remember that in the future ...

Thanks
Dave

User avatar
hk
Administrator
Posts: 10403
Joined: Sun Mar 26, 2006 9:34 am
Location: Haren, Netherlands

Re: Problem 2

Post by hk » Sat Nov 22, 2008 8:16 pm

Snipped out possible spoilers.
I don't think that makes for an efficient method: floats are slow compared to integers, moreover simple adding is much faster than multiplying or taking powers.
My prog based on the pdf runs in 0.003 milliseconds on a more than 4 years old computer using Delphi. (25 times as fast as yours)
Please do not post things like this again in the public part of this forum.
Image

chinesefishmarket
Posts: 4
Joined: Fri Nov 28, 2008 7:43 pm

Re: Problem 2

Post by chinesefishmarket » Fri Nov 28, 2008 7:49 pm

I'm having trouble with getting an answer for #2.
I have tried it for smaller numbers (limit 55) and I get 44 (34 + 8 + 2) for the answer. When I enter 4000000 as my limit, I get the wrong answer. Is there something I am missing about this problem?

User avatar
ed_r
Posts: 1009
Joined: Sun Jul 29, 2007 9:57 am

Re: Problem 2

Post by ed_r » Fri Nov 28, 2008 8:38 pm

Probably. Keep plugging away at it; you'll get there in the end. Good luck 8-)
(please note: this is not a hints forum!)
!647 = &8FDF4C

chinesefishmarket
Posts: 4
Joined: Fri Nov 28, 2008 7:43 pm

Re: Problem 2

Post by chinesefishmarket » Fri Nov 28, 2008 9:19 pm

But if it works for a smaller number, it should work for a larger number as well.
I think the problem is my answers are coming out to be in the format X.XXXe+00X, because I tried problem 6 and it also said it was wrong.

So if my answer is 1.111e+003, the correct answer should be 1111 right?
(^ not an answer I got for either problem, just the same format).

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

Re: Problem 2

Post by stijn263 » Fri Nov 28, 2008 9:22 pm

try using integers instead of floats/doubles.

what programming language do you use?

chinesefishmarket
Posts: 4
Joined: Fri Nov 28, 2008 7:43 pm

Re: Problem 2

Post by chinesefishmarket » Fri Nov 28, 2008 9:25 pm

stijn263 wrote:try using integers instead of floats/doubles.

what programming language do you use?
C++

chinesefishmarket
Posts: 4
Joined: Fri Nov 28, 2008 7:43 pm

Re: Problem 2

Post by chinesefishmarket » Fri Nov 28, 2008 9:27 pm

chinesefishmarket wrote:
stijn263 wrote:try using integers instead of floats/doubles.

what programming language do you use?
C++
OK. Forcing everything to be int works out great.
Thank you.

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

Re: Problem 2

Post by stijn263 » Sat Nov 29, 2008 10:41 am

Yup, you should avoid using doubles unless you have a good reason for using them. All projecteuler problems have answers smaller than 263, so using long long int will be sufficient.

If you're using cout to output your numbers, you can change the precision of the double output by setting: cout.precision(15);

Ints will always be fully shown.

phillyj
Posts: 2
Joined: Fri Oct 15, 2010 8:10 pm

Problem 002

Post by phillyj » Fri Oct 15, 2010 8:16 pm

Hi, I looked over a previous post on #2 but I'm still confused. In my understanding, am I to find:

[1] the sum of all the even numbers and the sum should be less than or equal to 4 million?

[2] the sum of the even numbers under each of which is less than or equal to 4 million? In this case, the answer can be greater than 4 million.

Which way am I supposed to solve it?

Thank you

Susanne
Posts: 32
Joined: Sun Nov 08, 2009 7:39 am

Re: Problem 002

Post by Susanne » Fri Oct 15, 2010 8:44 pm

It is case [2]. Each of the numbers must be smaller or equal 4 million.
Last edited by Susanne on Fri Oct 15, 2010 9:53 pm, edited 1 time in total.
Image

phillyj
Posts: 2
Joined: Fri Oct 15, 2010 8:10 pm

Re: Problem 002

Post by phillyj » Fri Oct 15, 2010 8:56 pm

I give up...for today. I thought I got the numbers but I keep getting it wrong. My code must be bad. I'm using matlab.

Post Reply