primes

Given that the inputs can be up to 1000000000, how can I write a more time and memory efficient program? (print all primes between m and n)

◇◆丶佛笑我妖孽 提交于 2020-12-13 09:40:21
问题 Here is the code below (ans to a CP qs) The time limit for execution is 6 seconds but my code is slower than. How can I make it more memory and time efficient ? Input: the input begins with the number t of test cases in a single line ( t <= 10 ). In each of the next t lines there are two numbers m and n ( 1 <= m <= n <= 1000000000 , n-m <= 100000 ) separated by a space. Output : for every test case print all prime numbers p such that m <= p <= n , one number per line, test cases separated by

Better way to find all the prime factors of huge integers in C?

前提是你 提交于 2020-07-10 08:25:10
问题 I have written a code in C that basically makes a list of all the prime factors of a huge number, which is stored using the gmp library. Here it is : int is_div(mpz_t number, mpz_t i) { return mpz_divisible_p(number,i)!=0; } mpz_t * prime_divs(mpz_t number){ mpz_t * prime_dividers = NULL; mpz_t i, i_squared,TWO, comp; mpz_inits(i, i_squared, TWO, comp, NULL); mpz_set_ui(i,2); mpz_mul(i_squared, i ,TWO); while(mpz_cmp(i_squared,number)<=0){ if(is_div(number,i)){ mpz_fdiv_q(comp, number, i); if

python - finding circular prime number

久未见 提交于 2020-06-27 19:44:11
问题 I am trying trying to find the number of circular primes from a given limit. The prime(x) will return whether a number is a prime or not. The rotations() will return a list of rotated numbers. Lastly, prime_count() will output the total amount of circular primes based on the given limit. Both prime() and rotations() gave me the correct output; however, prime_count() is not incrementing like it should. Any ideas on what i did wrong? def prime(number): #return true or false return all(number% i

python - finding circular prime number

那年仲夏 提交于 2020-06-27 19:43:10
问题 I am trying trying to find the number of circular primes from a given limit. The prime(x) will return whether a number is a prime or not. The rotations() will return a list of rotated numbers. Lastly, prime_count() will output the total amount of circular primes based on the given limit. Both prime() and rotations() gave me the correct output; however, prime_count() is not incrementing like it should. Any ideas on what i did wrong? def prime(number): #return true or false return all(number% i