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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:48:50+00:00 2026-06-09T21:48:50+00:00

The following code for prime sieve is not working with Release mode ,,but works

  • 0

The following code for “prime sieve” is not working with Release mode ,,but works perfectly with Debug mode.. I cannot figure out why ,, am using Microsoft Visual c++ 2010 express

#include <iostream>
#include <fstream>
#include <cmath>
#include <time.h>
#include <vector>
using namespace std;
void main(){

    clock_t start= clock();

    int n = 10000000;
    bool* primes= new bool[n];
    primes[0]=0;
    int g = (int)sqrt(n*1.0) +1;
    for (int i = 2 ;i <g ; i++){
        if(primes[i]){
            for (__int64 j = i*i ; j <n ; j+=i)
                primes[j]=0;
        }

    }
    printf("Time elapsed: %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);

    int* p = new int[n/2];
    int c = 0;
    for (int x = 0 ; x<n ; x++)
        if (primes[x]){
            p[c]=x;
            c++;
        }

    cout<<p[481516]<<endl;
    system("pause");
}
  • 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-09T21:48:51+00:00Added an answer on June 9, 2026 at 9:48 pm

    You haven’t initialized the rest of the values in your primes array before you start accessing them. Try adding

    for (int i=1; i<n; i++)
        primes[i] = 1;
    

    before your calculation of g.

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

Sidebar

Related Questions

I have the following code which spits out prime numbers between 1 and N.
This c++ code prints out the following prime numbers: 3 5 7 11 13
I tried sieve of Eratosthenes: Following is my code: void prime_eratos(int N) { int
I am using the following code snippet to calculate a total price. This works
The following code generates prime from 1 to n: (defun prime-list(n) (let ((a)(b)(x (floor
Following is the piece of code that i wrote to calculate the nth prime
The following code that prints some primes using sieve generates SIGSEGV error on an
I have the following code that implements the Sieve of Eratosthenes: primes :: [Int]
I am using the following code for the Share Price Application I have been
I the following code returns every text that has the price class associated to

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.