Number of preliminary factors of an integer is O(log(n)) [closed] - primes

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
It is known that every integer N can defined of multiplication of prime factors. for example the number 48 can be written as 48 = (2^4)*(3^1).
How can I proof that the count of the prime factors of an integer N (includes repeating the numbers if needed) is a number of O(log(n))?
(For the example above, log(48) = 5.584... and the count of prime factors is 4+1=5. and 5 <= 5.584 indeed)
Thanks.

Logarithm is the inverse of exponentiation. Exponentiation is repeated multiplication. Therefore, the logarithm is an approximation of the number of factors in a multiplication.
The longest possible chain of multiplications, i.e. the highest number of factors will be when you multiply lots of very small numbers. The smallest possible (reasonable) factor is 2, therefore the highest number of factors will be when you multiply by 2 a lot of times.
Multiplying by 2 a lot of times is the same thing as raising 2 to a power. The inverse of that is the logarithm in base 2.
Therefore, the number of prime factors will always be less than or equal to the logarithm base 2.
You don't even need Bachmann-Landau Notation for this, you can give pretty precise bounds, for an integer n, the number of prime factors |𝒫(n)| is: 1 ≤ |𝒫(n)| ≤ log2 n.

Related

Floating point number answer difference between c++ and calculator [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am calculating a floating point number by formula: number=1/(n-2.001)
Where n is any integer from 1 to infinite.
But it give me different answer in laptop and scientific calculator.
C++ calculation : 0.333444
Calculator answer: 0.3334444815
I have to get all digits in c++. How i get this.
Decimal equivalent of 1/3 is 0.33333333333333….
An infinite length number would require infinite memory to store, and we typically have 4 or 8 bytes. Therefore, Floating point numbers store only a certain number of significant digits, and the rest are lost.
NOTE : When outputting floating point numbers, cout has a default precision of 6 and it truncates anything after that.
The precision of a floating point number defines how many significant digits it can represent without information loss.
Therefore in your case only 6 decimals points are outputted and rest are turncated
To change the Precision of floating-point data types in C++ check this

Numerical stability of double zero [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a vector that contains non-negative doubles. I want to distinguish the cases when an entry is equal to zero and when an entry is greater than zero.
Is it numerically safe to just check if(a>0.0) or can this cause problems? I have no a-priori lower bound for the non-zero values, except machine precision. Should I create a helper-vector containing integers to mark the zero-values for safe checking?
For better understanding: The entries of the vector are something like weights on a graph, and I figured I don't need the adjacency matrix to keep track of the graph topology.
EDIT: My question is: Can and will 0.0 be exactly represented in doubles?
Floating point numbers aren't literally evil. Nor are they designed by stupid people. The one and only issue you need to concern yourself with here, is that of rounding.
A number which is set to zero, will be zero. There would be no reason to design a computational system which did not behave this way.
A number which is set to 0.1 will not be 0.1, because 0.1 is not exactly representable and is therefore rounded to the nearest representable number; see Is floating point math broken? for details. But if you set two variables to 0.1 they will compare equal to each other, because 0.1 is rounded the same way each time. (In fact the rounding happens during compilation; at runtime you're just setting the variable to the pre-rounded value.)
Similarly, a number which is set to 0.1 * 3 - 0.3 may not be equal to zero, because 0.1 was rounded, and then the rounded result was multiplied by 3 and that result was rounded, and so on.
So the issue is not one of representation, but of computation. If you set something to a particular value, that's the value it has. If it got there through a sequence of inexact computations, you can't rely on exact equality.

counting odd and even digts in a given number using 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 8 years ago.
Improve this question
How can I count the even and the odd integers in a given number in C++?
For example: The user inputs: 32478
output: 3 even numbers and 2 odd numbers.
The basic algorithm is:
Take the number modulo 2 (num % 2). If the result is 1 then the number is odd; increment the odd counter. If not then it's even; increment the even counter.
Divide the number by 10, dropping the remainder. (num /= 10)
Go back to step 1 if the number isn't zero.

how to differ rational and irrational number in C++ [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 9 years ago.
Improve this question
how to tell my float variable store an irrational number?
I'm a kind of newbie in C++
and I dont know many library function to be implemented
I want to make an exception for every calculation that end up being an irrational number
C++ doesn't have general arbitrary-precision rational numbers implemented. The available numbers are size-limited integers and floating point numbers.
A floating point number (in the common IEEE format) is however an integer multiplied by an exact power of two (positive or negative).
Even numbers like 0.1 = 1/10 are impossible to represent exactly because the denominator is not a power of two.
So the answer is simple :-) ... any number you will face with C++ is rational, more than that is an integer multiplied by a (possibly negative) power of two.
There are libraries implementing arbitrary precision integers and rational numbers, but they're not part of standard C++.
C++, by default, can only manage rational numbers. Moreover it's a very specific subset of the rationals where
The numerator is not too big in absolute value
The denominator is a power of two and it's not too big
When you write
double x = 1.0;
x = x / 10.0;
you get a result that is already outside of the capability of the C++ language because the denominator is not a power of two.
What the computer will do is storing into x a close approximation because 0.1 it's a number that cannot be stored exactly in IEEE double format.
Floating point numbers are an approximation of the number. It is accurate as best that it can do with the limited amount of room to play in.
So the best bet is to limit the effect of both. It is called algebra. Also enables one to reduce round errors.

Need help in mod 1000000007 [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm stuck in a problem in which I need to calculate something like:
((500!)/(20!x20!x20!x20!...)) mod 1000000007
I understand how to calculate 500!%1000000007 but I am not sure on how to distribute that operator in division.
I am currently trying to write a code which cancels the denominators by its numerator by its factors. But I am not sure if it is a good approach to this.
I just need a mathematical way of solving these kind of problems(mod1000000007) as they are regularly encountered in programming competitions and would help me to prepare for Google Code Jam.
Method 1:
Think of how you would compute 500! / (20! * 20! * 20! * ...) normally.
Don't multiply everything out and divide at the end. Do your divisions in the middle. Then combine this with the modulus reductions from your previous question.
Method 2:
Prime factorize 500! and 20!. Then subtract out the prime factors of 20! * 20! * 20! (or how ever many of them you have) from the prime factors of 500!.
Then rebuild the number by multiplying back the remaining factors together. (while taking modulus along the way to keep the number from getting large)
Method 3:
If 1000000007 (or whatever modulus) is prime, you can do divisions using the modular inverse.
Compute 20! mod 1000000007. Then compute it's modular inverse and multiply it into 500! mod 1000000007.