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

  • SEARCH
  • Home
  • 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 6126629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:23:58+00:00 2026-05-23T16:23:58+00:00

Project Euler problem 1 is: Find the sum of all the multiples of 3

  • 0

Project Euler problem 1 is: Find the sum of all the multiples of 3 or 5 below 1000

Here is my program, using two simple functions to work out the sum of all the multiples of 3 and all the multiples of 5 and then add them up:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;


int threeSum( void );

int fiveSum( void );


int main( int argc, char** argv )
{
    cout << "\n The sum of all the natural numbers below 1000 that are multiples of 3 or 5 = \n" << endl;

    cout << threeSum() + fiveSum() << endl << endl;

    system( "PAUSE" );
}


int threeSum( void )
{
    int sumSoFar = 0;

    for ( int i = 1 ; i < 1000 ; i++ )
    {
        if ( i % 3 == 0 )
                            sumSoFar = sumSoFar + i;
    }

    return sumSoFar;
}


int fiveSum( void )
{
    int sumSoFar = 0;

    for ( int i = 1 ; i < 1000 ; i++ )
    {
        if ( i % 5 == 0 )
                            sumSoFar = sumSoFar + i;
    }

    return sumSoFar;
}

which produces 266333 as the answer. Is this correct, or am I doing something wrong, as the website checker says this is the wrong answer!

  • 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-05-23T16:23:59+00:00Added an answer on May 23, 2026 at 4:23 pm

    As most others pointed out, you’re summing the multiples of 15 twice.

    Just a hint for another solution:

    The sum of multiples of 3 below 1000 is

    SUMBELOW(3,1000) = 3 + 6 + 9 + ... + 999 = 3*(1+2+3+...+333) = 3*333*(1+333)/2 = 3*((1000-1)/3)*(1+(1000-1)/3)/2
    

    (All divisions are integer divisions…)

    There are similar formulas for calculating the sums of multiples of 5 and 15. To get the overall result, you have to add the sums for 3 and 5 and subtract the sum for 15…

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

Sidebar

Related Questions

In Project Euler, a problem asks me to write a program to find the
The 10th problem in Project Euler: The sum of the primes below 10 is
I was trying to solve Project Euler problem 10 using python, but my program
I am trying to solve Project Euler problem in Clojure using recursion. The following
I'm doing problem 20 on Project Euler - finding the sum of the digits
I am using Haskell to solve problem 99 in euler project, where I must
I'm having some trouble with this problem in Project Euler. Here's what the question
I am working on Project Euler Problem 4 , and need to find the
I'm trying to find multiple ways to solve Project Euler's problem #13 . I've
I'm trying to solving Project Euler Problem 14 . It asks to find the

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.