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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:33:04+00:00 2026-06-18T01:33:04+00:00

I was just looking at some algorithms for prime numbers and came across this:

  • 0

I was just looking at some algorithms for prime numbers and came across this:

for(int i=2;i*i <= n;i++)
{/*assume no operations here*/} 

I was just wondering if the above loop will be faster than the following or not?

int x=sqrt(n);
for(int i=2;i<=x;i++)
{/*nop*/}
  • 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-18T01:33:05+00:00Added an answer on June 18, 2026 at 1:33 am

    It depends on the value of n, of course. Anyway, sqrt() is not guaranteed to give you the right result: due to rounding reasons, you might end up with a value of x which is one less than expected and ruin the algorithm. Rather than going for a micro-optimisation, I would stick to correctness here and use the original version, which is guaranteed to give correct results.

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

Sidebar

Related Questions

Really quick here... I think I have the answer, but just looking for some
I'm looking to add some genetic algorithms to an Operations research project I have
This isn't actually homework, I'm just looking through some questions in a discrete maths
I'm just looking for some direction when it comes to NHibernate and WCF. At
Maybe a browser plugin? Just looking for a dirty, quick way to test some
I'm looking at some vb.net code I just inherited, and cannot fathom why the
I'm looking for a way to group some ui elements together just like the
To debug some JavaScript code, I am looking for JavaScript code (preferably just js,
I was just doing some random testing on locking in multi-threading this morning and
I'm looking for some pointers here as I don't quite know where to start

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.