Number of prime number between 1 and n [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have been surfing on the internet and found an interesting video in which is mentioned that you can find number of primes between 1 and any number n using Riemann hypothesis and Riemann zeta function. My math knowledge is not this high and I don't understand how, using zeta function, can one find number of primes.
I wanted to write a program that takes one number as input and outputs number of primes to that number, which is calculated using aforemention zeta function, but I have no idea where to start learning. Please know that I'm 17 years old and have always loved math and programming but this is something totaly new to me. Any help is apreciated.

There are some formulas, but the best we have so far is only asymptotic estimates.
It is shown that if we denote with π(n) the number of primes that do not exceed n then the fraction:
π(n) * ln(n) / n
can be arbitrarily close to 1.
This is the prime number theorem.

Related

Calculate using Rational Index Binomial Theorem in C [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I have tried so many ways to calculate using this binomial theorem but I still couldn't find one:
The value of x and n is given for example b=0.5 and n=8
I know for the factorial we have to use loop but the numerator part is a little bit tricky.
Obviously I know how to code for (1+b)^n, but the question is still asking for the coding for binom theorem.
For example if the value of x is 0<x<1 and n is any positive integer, what will the value of (1+x)^n will be using the binomial theorem?
I understand that you know how to calculate the left side of the equation in programming.
I understand that you also know how to program the right side, apart from the problem that it is an infinite loop; but you want it to end at some point and have a result.
By the math theory ending early means a wrong result.
But in programming you will have problems with restricted precision of floating point math anyway. So you can take shortcuts to solve your problem.
In the comments you find recommendations how to do the calculation of each step efficiently. I will only focus on the end condition.
Write a loop calculating more and more precise steps.
End the loop when a freshly calculated (intermediate) result is the same as the previous one. With floating point representation having restricted precision that will sooner or later happen and the result will be within only one "minimal rounding" of the correct result.
Note:
In order to avoid the restricted precision getting in the way at the wrong place, I recommend to calculate the parts (as described in the recommendation in comments) in double and the intermediate results (those you compare for the loop condition) into a float variable.

Algorithm for "erase as few numbers as possible to make remaining in increasing order" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I’m reading "Introduction to Algorithms: A Creative Approach" and met this question in Chapter 1:
Problem 1.3: You have a list of numbers, erase as few numbers as possible to make remaining numbers in increasing order.
For example, given the array
9 44 32 12 7 42 34 92
Two possible options are 9 12 42 92 and 32 42 92, and the former has fewer numbers removed.
I tried a recursive algorithm but not satisfied with its performance, because it still need to test too many combinations. I found a heuristic algorithm that can get good result fast, though I'm not sure if it can guarantee the best result. I searched online but didn't find any discussion on this question. I believe there should be a better algorithm.
I wrote my 2 methods here in case you want to check.
UPDATE: I was asking solutions to this question, #josilber and #templatetypedef gave the links and the right direction to look at. It turned out that this is a special case of a family of known problems with good solutions. There is no need to write detailed solution here, the wiki page of Longest increasing subsequence, Patience sorting provided detailed information.
It's worth noting that although the answers have some links, this question is not about asking for resources or links. The real answer is the knowledge of "this question is a variation of some known solved problems".
As a hint, this is equivalent to finding the longest increasing subsequence of the array (do you see why?) Since that's a standard algorithm with known O(n log n) solutions, you should be able to solve the problem with a slight modification of LIS.
Hope this helps!

How to define vectors of complex numbers with random values of size N in C program [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am a beginner, how to define vectors of complex numbers with random values of size N in C program. With this code
complex*vector=(complex*)malloc(sizeof(complex)*N)
You have two separate problems, both of which are already answered.
How work with complex numbers: How to work with complex numbers in C?
How to make an array of random numbers: To generate array of random numbers in a given range in "C"

C: How to get a 4096 bit prime number? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
How to get a random, really big (f.e. 4096 bit) prime number in C?
Does anyone know a good Library for this?
Your best bet is libgmp.
It has a function that will scan for the next prime number (using Miller-Rabin) starting from some starting number.
void mpz_nextprime ( mpz_t rop, mpz_t op );
Set rop to the next prime greater than op.
This function uses a probabilistic algorithm to identify primes. For practical purposes it's adequate, the chance of a composite passing will be extremely small.
Is the function you want.
You just roll a random number with as many bits as you need and then fire mpz_nextprime. Runtime should be somewhere around O(log(op)) (probabilistic).
You will also need one of the random number generators.
Generally you generate a large random number, using a strong random number generator (e.g. on Windows use CryptGenRandom), then apply some checks to determine whether it is likely to be prime.
The only way to check that it really is prime is to try dividing by every number between 1 and (potential-prime / 2). If any of them divides equally with no remainder, it's not prime. Since that will take an infeasibly long time to compute (that's the whole point of using really big prime numbers), the tests used are far simpler and based on the probability that the number is unlikely to have easily guessable factors.
If you're implementing software that uses encryption, I strongly recommend that you use a NIST-certified cryptographic library or module to generate your keys and do the encryption.

Finding abundant numbers from 1 to 10 million using a sum [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
My task is to implement algorithm in C of finding abundant numbers from 1 to 10 million. Therefore I don't really understand mathematics.
There is several ways how to do it, but efficient and fast (for that BIG input 10 mil) might be by summing - NOT dividing, NOT multiplying, NOT EVEN using remainder after the division. Just sum.
But I'm really confused WHAT to sum. Please guys help, appreciate every single answer.
Only I know is that there are 2476736 abundant numbers under 10
million, common computer hardware is not able to check it even in
hours, so I need more efficient algorithm and I know it's able to run
under a second.
you could try this by counting all the multiples of an abundant number upto 10 million
suppose 12 is the first abundant number you found then 24 would definetly be abundant hence you can count all the multiples of 12 upto the limit you wish then go for the next number.I don't know how fast or efficient it would be.

Resources