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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:47:57+00:00 2026-06-14T02:47:57+00:00

I wanted to solve a question from project euleur about finding the largest prime

  • 0

I wanted to solve a question from project euleur about finding the largest prime number of a big number. I run my code on a virtual machine on Visual studio 2012, and the code seems froze. When I step into the loop, the code works well, but when I execute it, the console is always there. It is as if the program is still running. Could it be that the program takes time to execute?

My Code

static void Main(string[] args)
{
    long number = 5;

    for (long i = 1; i < 600851475143; i++)
    {
        if (i % 2 != 0 && i % 1 == 0 && i % i == 0)
            number = i;
    }

}
  • 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-14T02:47:59+00:00Added an answer on June 14, 2026 at 2:47 am

    I ran this bit of code and it does take a while to run, but it does seem to progress (i does increment). Try this to determine whether i is a prime:

        public static bool IsPrime(long candidate)
        {
            // Test whether the parameter is a prime number.
            if ((candidate & 1) == 0)
            {
                return candidate == 2;
            }
            // Note:
            // ... This version was changed to test the square.
            // ... Original version tested against the square root.
            // ... Also we exclude 1 at the very end.
            for (int i = 3; (i * i) <= candidate; i += 2)
            {
                if ((candidate % i) == 0)
                {
                    return false;
                }
            }
            return candidate != 1;
        }
    

    I can’t claim credit for this. It is from http://www.dotnetperls.com/prime.

    Add some Console.WriteLines to your main method to its progress:

        static void Main(string[] args)
        {
            long number = 5;
    
            for (long i = 1; i < 600851475143; i++)
            {
                if (IsPrime(i))
                {
                    Console.WriteLine(i);
                    number = i;
                }
            }
        }
    

    There’s other resources out there for these algorithms too:
    http://csharpinoneroom.blogspot.com/2008/03/find-prime-numer-at-fastest-speed.html

    Good luck!

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

Sidebar

Related Questions

I've asked the same question some days ago, but there I wanted to solve
here is another question about how to next detailView like in Mail-App from me.
I recently wanted to see if I am able to solve an easy sudoku
Wanted to know if there was a way one could query shelveset details from
Wanted to know if someone had a suggestion on code or maybe there's a
just wanted to ask where I define initial class properties? From other languages I
I wanted to know about Data Type implementation in PHP so I need a
Maybe it's a simple question but I didn't succeed to solve it. DNSperf is
If you came here from Google looking for model to dict, skip my question,
In my previous question How to find the unique serial number of a flash

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.