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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:32:10+00:00 2026-05-25T19:32:10+00:00

I solved problem 10 in project euler (but my solution took 2000 seconds), so

  • 0

I solved problem 10 in project euler (but my solution took 2000 seconds), so I tried to find faster solution. I found this (execution time 0.1 sec), but I don’t understand this solution and I need help.

#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
#define HIGHEST 2000000

char Prime[HIGHEST / 2];

int main(int argc, char** argv)
{
   unsigned int i, j;
   unsigned long long sum = 2;
   unsigned int total = 0;

   /* Set entire array to true (prime) */
   memset(Prime, 1, sizeof(char)*HIGHEST / 2);
   /* except for 1 */
   Prime[0] = 0;

   for(i = 3; i < HIGHEST; i += 2) {
      if(Prime[i / 2] == 1) {
         sum += (unsigned long long)i;
         total++;
      }
      for(j = (i+i+i)/2; j < HIGHEST/2; j += i) {
         Prime[j] = 0;
      }
   }
   printf("Sum: %llu (%d prime numbers)\n", sum, total);
   return 0;
}
  • 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-25T19:32:11+00:00Added an answer on May 25, 2026 at 7:32 pm

    The solution is a somewhat strange version of the Sieve of Eratosthenes. It looks like the writer was trying to prematurely optimise by doing some sneaky tricks with the loop counter, i.

    I suggest that you work through the first few iterations of the loop on paper to get a feel for what the code is doing.

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

Sidebar

Related Questions

Solved the problem see the bottom of my post. So I have a simple
I have this project set up with EF4 and I'm using LINQ to Entities
I'm using Phing to set up a build process for a large PHP project.
We have in one of our applications a single eclipse project that contains all
I have been working on a small file manager module in a project where
I had 11 or so Rspec tests running sat, until I converted my project
I am working on a project where the name of our assets folder is
I'm having an odd problem with asp.net MVC razor view. I want my model
I'm running Eclipse Helios Service Release 1, with Tomcat 7.0.12 in Linux Ubuntu Natty
I am experimenting with Flask coming from Django and I really like it. There

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.