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 8695551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:03:57+00:00 2026-06-13T01:03:57+00:00

http://projecteuler.net/problem=1 If we list all the natural numbers below 10 that are multiples of

  • 0

http://projecteuler.net/problem=1

If we list all the natural numbers below 10 that are multiples of 3 or
5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the
sum of all the multiples of 3 or 5 below 1000.

If I change “int maxNum” to 10 or any other small number like 20, I’m getting the right answer.

But somehow when I do it with a big number like 1000, it will give me a number which I don’t expect to come, I don’t know why, please help.

Does it do it because it has reach the max value of an int?

class Program
{


    static void Main(string[] args)
    {
        //TASK: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
        //Find the sum of all the multiples of 3 or 5 below 1000.

        int multiplierA = 3;
        int multiplierB = 5;

        int maxNum = 1000;
        int i = 1;

        int deelEen = MultiplyFactory(multiplierA, i, maxNum);
        int deelTwee = MultiplyFactory(multiplierB, i, maxNum);

        int result = deelEen + deelTwee;

        Console.WriteLine(result);
        Console.Read();
    }

    static int MultiplyFactory(int multiplier, int i, int maxNum)
    {
        List<int> savedNumbers = new List<int>();
        while(multiplier*i < maxNum)
        {
            savedNumbers.Add(multiplier*i);
            i++;
        }

        int answer = 0;
        foreach(int getal in savedNumbers)
        {
            Console.WriteLine(getal);
            answer = answer + getal;
        }
        savedNumbers.Clear();
        return 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-06-13T01:03:59+00:00Added an answer on June 13, 2026 at 1:03 am

    I think the problem is that you need to find sum of all the multiples of 3 OR 5. And what your program is doing is finding sum of all multiplers of 3 + sum of all multipliers of 5.
    You can return arrays of int and then sum distinct numbers from arrays.

    You can also use Linq to get distinct values from lists

    class Program
    {
        static void Main(string[] args)
        {
            //TASK: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
            //Find the sum of all the multiples of 3 or 5 below 1000.
    
            int multiplierA = 3;
            int multiplierB = 5;
    
            int maxNum = 1000;
            int i = 1;
            int result = 0;
    
            List<int> deelEen = MultiplyFactory(multiplierA, i, maxNum);
            List<int> deelTwee = MultiplyFactory(multiplierB, i, maxNum);
    
            foreach (int val in deelEen)
                result += val;
    
            foreach (int val in deelTwee)
                if (!deelEen.Contains(val)) result += val;
    
            Console.WriteLine(result);
            Console.Read();
        }
    
        static List<int> MultiplyFactory(int multiplier, int i, int maxNum)
        {
            List<int> savedNumbers = new List<int>();
            while (multiplier * i < maxNum)
            {
                savedNumbers.Add(multiplier * i);
                i++;
            }
    
            return savedNumbers;
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is problem about sum of factorial of digit http://projecteuler.net/index.php?section=problems&id=254 also here is Define
I'm trying to solve a mathematical problem from http://projecteuler.net using javascript: to find the
I'm working on problem 14 of Project Euler ( http://projecteuler.net/problem=14 ). I'm trying to
For example, solving the following problem http://projecteuler.net/problem=5 I came up with the following solution
I'm new in Haskell and try to solve 3 problem from http://projecteuler.net/ . The
http://projecteuler.net/problem=20 I've written code to figure out this problem, however, it seems to be
In problem 4 from http://projecteuler.net/ it says: A palindromic number reads the same both
I have got this large list of names here http://projecteuler.net/project/names.txt , which I am
I am trying to resolve Euler Problem 18 -> http://projecteuler.net/index.php?section=problems&id=18 I am trying to
From http://projecteuler.net/index.php?section=problems&id=99 Comparing two numbers written in index form like 2 11 and 3

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.