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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:43:52+00:00 2026-05-19T13:43:52+00:00

I am working on solving Euler project 3: Description: The prime factors of 13195

  • 0

I am working on solving Euler project 3:

Description: The prime factors of 13195 are 5, 7, 13 and 29.
             What is the largest prime factor of the number 600851475143 ?

This is my code to generate the answer. However I need an integer type to hold 600851475143. When I compile this on GCC on a Mac I get:

integer constant is too large for ‘long’ type". 

I expect long long could easily hold this number. I also tried making it unsigned. Why doesn’t my code hold that small number and what can I do to make it work?

#include <iostream>
#include <vector>

using namespace std;

static bool IsPrimeFactor(int numToTest,int testNum,vector<int> factors)
{
    if(numToTest%testNum==0) // is it a factor?
    {
        // see if it is a prime factor
        for(unsigned int i=0; i < factors.size(); i++)
        {
            if(testNum%factors[i]==0)  // see if this factor
            {                          //is divisble by one we have already

                return false;
            }
        }

        return true;
    }
    return false;
}

int main() {
    unsigned long long numToTest=600851475143;
    unsigned int testNum=2;  // 0 and 1 are assumed
    vector<int> factors;   

    while(testNum<numToTest)   // don't go higher than the max num
    {
        if(IsPrimeFactor(numToTest,testNum,factors)) // is it a factor?
        {
            factors.push_back(testNum); // got through prime factors 
        }                                   // and none divided it

        testNum++;
    }

    for(unsigned int i=0; i < factors.size(); i++)
    {
        cout << "factor " <<factors[i] << endl;
    }

    cout<<"Highest factor: " << factors[factors.size()-1]<<endl;

    return 0;
}
  • 1 1 Answer
  • 2 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-19T13:43:53+00:00Added an answer on May 19, 2026 at 1:43 pm

    Check this question. You have to specify your literal like this:

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

Sidebar

Related Questions

I'm have been working on solving Project Euler #14 for a while now in
I'm working on solving the Project Euler problem 25: What is the first term
I've started working on some Project Euler problems, and have solved number 4 with
Working on the problems on Project Euler to try to learn Clojure. I'm on
I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit
Summary: How would I go about solving this problem? Hi there, I'm working on
I'm working on problem 14 of Project Euler ( http://projecteuler.net/problem=14 ). I'm trying to
I'm trying to solving Project Euler Problem 14 . It asks to find the
I've been working on some problems/exercises on Project Euler hoping to practice/learn some optimal
To help me learn Haskell, I am working through the problems on Project Euler.

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.