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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:50:21+00:00 2026-05-27T16:50:21+00:00

for (long long j = factored_num / 3; j > 2 || factored_num !=

  • 0
for (long long j = factored_num / 3; j > 2 || factored_num != 1; j -= 2) {

On a 64-bit computer, I’m trying to factor a number. This code works perfectly fine when long long j = factored_num, but when I do integer division, cout << j shows that j is negative — I’m assuming it overflows. How can I fix this?

I’ve tried 3LL, j-= 2LL, etc. in case it was a type problem. Again, it definitely has to do with the division part, but I’m not familiar enough with data types to immediately get the problem.

  • 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-27T16:50:22+00:00Added an answer on May 27, 2026 at 4:50 pm

    The problem could be the final condition. You loop while j is more than 2 or factored_num is not 1, so if factored_num does not become one, the loop will not end and j will continue to decrement to negative numbers.

    I’d expect the condition to be j > 2 && factored_num != 1, that is you want to end if j is 2 or less (why 2; 2 is a valid factor) or factored_num is 1 (and therefore does not have any more factors).

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

Sidebar

Related Questions

Long story short Say I have the following code: // a class like this
Long winded title, short question: If one wants to develop for Windows but not
Long-Winded Background I'm working on parallelising some code for cardiac electrophysiology simulations. Since users
long time listener first time caller... I have this function (I don;t recall where
Long story short, I have a long code that uses jQuery. Lots of files,
Long story short: in a C# application that works with COM inproc-server (dll), I
Long ago, I looked at this MSDN walkthrough . It implements a color editor,
long number = …; // string should contain exactly 12 characters string leastSignificant48bitsOfNumberAsHex =
long lastmodify = f.lastModified(); System.out.println(File Lost Modify:+lastmodify); I am running the above code of
I've been glancing at this code for a while now, and I can't seem

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.