c# - Project Euler #3 STUCK -


I really did not want to go to it, it is through PE that I should try to solve myself Problems to

The first two I had managed in less than an hour, unfortunately I was completely trapped in the problem 3. Now I have tried the traditional method of division by testing Of course this is very slow, I've tried split by sqrt (n) Sector to optimize split testing, but just to get the highest primary factor 600,851,475,143 also very slow.

I have also tried to use the sneaky erotostinase for which I have to admit that I understand hardly, but it is still not cutting First, all the "numbered" numbers are omitted because an exception is thrown because the amount of entries becomes huge when you try to generate all prime up to 600,851,475,143.

I am trapped and very clearly I am in one place. I am starting to get annoyed with this time ..

Here is my code:

  class program {// Main reason 13195 5, 7, 13 and 29 are // 600851475143 What is the biggest major factor of numbers? Fixed Zero main (string [] ARGs) {console. Weird (GetHighestPrimeFactor (600851475143) .ostring ()); Console.ReadKey (); } Fixed list & lt; Long & gt; GeneratePrimeNumbers (long n) {// Let's mark marked Er as the number of Eratosthenes = new list & lt; Long & gt; (); Var primes = new list & lt; Long & gt; (); (Long time I = N / 2; i & lt; n; i ++) {// If this is incorrect then this is a major number, add it to the list of preferences if marked (marked. ) {Primes. Couples (i); For (long jm = i; j & lt; = n; j + = i) {marked digits Add (J); }}} Returns Primes; } Stable long GetHighestPrimeFactor (long n) {var primes = GeneratePrimeNumbers (n); // loop returns back and when we first (first I = n / 2; i & gt; 1; i--) (if (n% i == 0) {if (primes.Contains (i) ) {Return i;}}} // code execution return will not reach this point of -1; The point of PE course is that I should try to solve I    

own problems

OK, so here are some hints rather than an answer

I did not think sqrt (n)

by testing How it does help Suppose that you are trying to find the biggest factor of 74. The square root of 74 is 8 point something how does it help 74 to 8. Does anything help?

Now I have tried to use the sieve of erotinithines for this too.

is the prime number to find sieve. Is your theory that you want all the major numbers to the desired number Want to find and then most of them Divide the number of d?

It is very expensive for a large number of computationals.

Here are your hints:

  • If a number n & gt; 0 is the prime, then it is your biggest prime divisor

  • If a number is n & gt; 0 is composite, then it is x * y where neither 1.

  • One of these numbers is equal to or less than the square root of n.

  • The biggest factor of N is either the biggest factor of X or the biggest factor of the Y.

    If you can not understand why one of these facts is true, stop and think about it unless you do . You will not find anywhere on Euler's next problems until you find it cold.

    Now with those signals you should be able to break the problem down in order of small problems.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -