Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8998615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:03:40+00:00 2026-06-16T00:03:40+00:00

I have a Haskell solution to Project Euler Problem 2 which works fine for

  • 0

I have a Haskell solution to Project Euler Problem 2 which works fine for the four million limit, as well as for limits up to 10^100000, taking only a few seconds on my machine.

But for anything bigger, e.g. 10^1000000, the computation does not return in good time, if at all (have tried leaving it for a couple of minutes). What is the limiting factor here?

evenFibonacciSum :: Integer -> Integer
evenFibonacciSum limit = 
  foldl' (\t (_,b) -> t + b) 0 . takeWhile ((<=limit) . snd) . iterate doIteration $ (1,2) where
    doIteration (a, b) = (twoAB - a, twoAB + b) where
      twoAB = 2*(a + b)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:03:40+00:00Added an answer on June 16, 2026 at 12:03 am

    The problem is that you are summing the (even) Fibonacci numbers. That means you have to calculate them all. But

    F(n) ≈ φ^n / √5, with  φ = (1 + √5)/2
    

    So you are adding a lot of numbers of large size, Θ(n) bits for F(n). For a limit of 10^1000000, you need about 800000×2 additions of numbers larger than 10^500000. In general, you need Θ(n) additions of numbers with Θ(n) bits.

    Adding numbers of d digits [in whatever base] is an O(d) operation. So your algorithm is quadratic in the exponent.

    To avoid that, find a closed formula for the sum S(k) of the first k even Fibonacci numbers (hint: it’s a relatively easy formula involving one Fibonacci number), find the largest k so that F(3*k) <= limit, and compute the sum using the formula and the algorithm to compute F(n) in O(log n) steps e.g. here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit
I'm a beginner to Haskell and I'm having trouble with Project Euler Problem 10
I'm working on Project Euler Problem 14. Here's my solution. import Data.List collatzLength ::
I've been doing project Euler problems to learn Haskell. I've have some bumps on
I have the following solution in Haskell to Problem 3 : isPrime :: Integer
im searching for a solution for my Haskell class. I have a list of
I have a problem with protocol-buffers in Haskell. I'm writing a simple UDP receiver
While solving some Project Euler Problems to learn Haskell (so currently I'm a completly
When programming in Haskell (and especially when solving Project Euler problems, where suboptimal solutions
I have a constraint problem I've been working on, which has a couple fun

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.