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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:57:55+00:00 2026-06-16T06:57:55+00:00

I have this simple program: // Include libraries #include <iostream> #include <string> #include <vector>

  • 0

I have this simple program:

// Include libraries

#include <iostream>
#include <string>
#include <vector>

using namespace std;

// Include locals

// Start

#define NUMBER 600851475143

int main(int argc, const char* argv[])
{
    long long int ans = 0;
    long long int num = NUMBER;

    vector<int> factors;

    do
    {
        // Get lowest factor

        for (int i = 1; i <= num; ++i)
        {
            if (!(num % i))
            {
                factors.push_back(i);

                num /= i;
                break;
            }
        }
    } while (num > 1);

    cout << "Calculated to 1.\n";

    int highestFactor = numeric_limits<int>::min();

    for (int i = 0; i < factors.size(); ++i)
    {
        if (factors[i] > highestFactor)
        {
            highestFactor = factors[i];
        }
    }

    ans = highestFactor;

    cout << ans << endl;

    return EXIT_SUCCESS;
}

compiling with g++ -O2 -c -o prob3.o prob3.cpp proved successful, but when I ran it I saw nothing and it just kept running and I had to Ctrl-C (force-kill) it in the end. When I try to add

int main(int argc, const char* argv[])
{
    cout << "Test\n";

to the program, Test didn’t get printed too. It’s like my program is not executed at all.

Any help or advice is appreciated!

Solution

I forgot prime numbers started at 2. Change for (int i = 1 to for (int i = 2.

  • 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-16T06:57:56+00:00Added an answer on June 16, 2026 at 6:57 am

    Those nested loops are going to loop forever. The inner for loop will only ever execute once because of the break so it will only ever do num /= 1. That means num never decreases and so num > 1 will never be false. I suppose you just need to wait longer!

    The reason you’re not seeing “Test” is probably because you haven’t flushed the output. Try:

    std::cout << "Test" << std::endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I have this simple c++ program #include <cstdlib> #include <iostream> #include <math.h> #include <stdlib.h>
I have this simple C program: #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <time.h>
I have this simple program #include <stdio.h> int main(void) { unsigned int a =
Let's consider this simple test program: #include <stdio.h> #include <string.h> int main(int argc, char
I have this simple program that computes salaries for four different worker types. It's
My situation is simple. I have this in my program: File folder = new
I have this simple rule in my Makefile : PP=g++ -std=c++0x %.o: $.cpp $(PP)
I have this simple code, using Joda-time. Works fine, but I have a problem.

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.