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

I solved a problem on Project Euler but it took about 4 minutes to
I tried to solve problem# 276 from Project Euler , but without success so
This is fairly 'math-y' but I'm posting here because it's a Project Euler problem,
I did this problem [ Project Euler problem 5 ], but very bad manner
I solved Problem 10 of Project Euler with the following code, which works through
I just solved the first problem from Project Euler in JavaFX for the fun
As some of you may notice this question is problem 16 from Project Euler
I'm again working on Project Euler, this time problem #4. The point of this
In Project Euler, a problem asks me to write a program to find the
There is another recent Project Euler question but I think this is a bit

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.