Finding abundant numbers from 1 to 10 million using a sum [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
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.

Related

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 find prime numbers when range is large? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
how to find all prime numbers between 1 and 10^9 , i know we can use Sieve_of_Eratosthenes for smaller range, but what when range is too large equivalent to 10^6 ?
Up to 10^9 is not really a big deal. First, only look at odd numbers (because there is only one even prime). Second, use a bit array, so you only need 500 million bits or about 62 Megabyte. Even straightforward code should do that in a few seconds at most.
If you go further, you'd do a sieve for numbers from 1 to 10^9, then from 10^9 + 1 to 2 * 10^9 and so on. Above 10^13 it gets interesting and you need to put a bit more effort into it.

Number of prime number between 1 and n [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 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.

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.

Printing range of number upward or backward according to users first input [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to print a range of integers (all the positive integers that to be found between the user's 2 input integers) and I need to do it by the order the user typed it.
for example:
for the input: 4,9 output would be: 4 5 6 7 8 9
and for the input: 9,4 the output would be: 9 8 7 6 5 4
I'm not allowed to use any array/strings/functions, just basic C commands.
Anybody have any ideas?
Since this is most likely a learning exercise, here are some points to think about:
You need a loop.
The loop starts at the first number the user enters, and ends upon reaching the second number
The step of the loop depends on the order of the numbers entered by the user
If the first number is smaller than the second one, the step of the loop is one
If the first number is larger than the second one, the step of the loop is negative one
Therefore, the structure of your program is going to be as follows:
Prompt the user for the two numbers
Read numbers one and two
Compute the step using an if
Print out the range using a loop (for, while, or do/while, it's up to you).
This should be enough to complete your assignment. Good luck!

Resources