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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:17:00+00:00 2026-05-29T19:17:00+00:00

This is my code : #include <iostream> using namespace std; int main() { long

  • 0

This is my code :

#include <iostream>

using namespace std;

int main()
{
    long int x = 1;
    long int res;

    while (x<600851475143)
    {
        x++;
        if(600851475143%x==0)
        {
            res=x;
            cout<<x<<"\n";
        }
    }
}

I don’t know whats wrong with it but it gives me this output :

839
1471
6857
59569
104441
486847
1234169
5753023
10086647
87625999
408464633
716151937
-716151937
-408464633
-87625999
-10086647
-5753023
-1234169
-486847
-104441
-59569
-6857
-1471
-839
-71
-1
Floating point exception

Process returned 136 (0x88)  execution time : 156.566 s
Press ENTER to continue.

and when i substitute 600851475143 with 13195 [ which was in the example ]…
it works fine…and gives me this output :

5
11
55
11149

Process returned 0 (0x0) execution time : 0.005 s
Press ENTER to continue.

I don’t know what i am doing wrong… :/
Perhaps my previous program didn’t run properly…i tried it with int in the beginning and then changed it to long int…No difference…

  • 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-29T19:17:01+00:00Added an answer on May 29, 2026 at 7:17 pm

    Negative values are due to overflow. Start by using unsigned integers instead of signed integers. In addition to that, in 32 bit computers, long int and int types are both 32 bits.

    unsigned long long int x = 1;
    unsigned long long int res;
    

    Also, you could emphasize the fact that those constants are unsigned

    while (x<600851475143U)
        {
            x++;
            if(600851475143U%x==0)
            {
                res=x;
                cout<<x<<"\n";
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand why this code #include <iostream> using namespace std; int main(){ int
This code: #include <iostream> using namespace std; int main() { cout << Hello world!\n;
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
Have a look at this code: #include <iostream> using namespace std; int main() {
This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
I have this code #include <iostream> using namespace std; class Test{ public: int a;
here is algorithm #include<iostream> #include<Windows.h> #include<time.h> using namespace std; int main(){ int a[10]={12,3,5,2,7,80,10,1,16,30}; long
Can anybody help me with this simple code?? #include <iostream> using namespace std; void
#include <iostream> #include <fstream> #include <cstring> using namespace std; typedef unsigned long int WORD;
Consider this code #include <iostream> #include <cstdio> using namespace std; class Dummy { public:

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.