Thursday 15 August 2013

algorithm - Paul Erdos Conjecture [Java] -


I'm trying to solve this one simple problem at SPOJ.

It needs a number of prime numbers (less than N) which can be expressed as X ^ 2 + Y ^ 4 (where x and y are integers).

I've killed an animal force, which takes a lot of time (n ~ = 1000000), which results in a TLE (time limit exceeded) error being thrown by the engine. Here is the source code:

  import java.io. *; Import java.util. *; Class HS08PAUL {Public Stable Ent [] Sieve (Int N) {Boolean [] Prime = New Bullion [N + 1]; Int [] primeNumbers = new int [n]; Int index = 0; Arrays.fill (primeNumbers, 0); Arrays.fill (prime, true); Head [0] = wrong; Head [1] = wrong; Int m = (int) Math.sqrt (n); For (int i = 2; i & lt; = m; i ++) {for (s [i]) (int k = i * i; k & lt; = n; k + = i) prime [K] = false; } For (int j = 2; j & lt; = n; j ++) {if (principal [j]) {primeNumbers [index] = j; Index ++; }} Return primetime; } Public static zero main (string [] args) {scanner = new scanner (System.in); {Try Double Number Opt Cascus = in.nextDouble (); While (Number of test cases -> 0) {int index = 0, y = 0, count = 0; Int num = in.nextInt (); Int [] primes = sieve (number); While (index and lieutenant; number / 3) {for (y = 1; y & lt; 57; y ++) {if (Math.ceil (Math.scrt (primes [index] - Math.pow (y, 4 )) == math.flur (mathematics.sqrt (primes [index] - Math .pow (y, 4))) {count ++; break; }} Index ++; } System.out.println (calculation); }} Hold (exception e) {}}}  

Is there any way I can work this approach?

PS: Please ignore uncontrolled exception handling.

How many numbers are x ^ 2 + y ^ 4 below 1000000? How many prime numbers are less than 1000000?

@ isnot2bad's comment is also relevant.


No comments:

Post a Comment