Totient(N) is a product of (P-1)(Q-1) and (P-1),(Q-1) will not be prime after taken 1 from them and multiple factors can be obtained? Is it true? Or can we find P and Q if we have totient of N?
Since only even prime is 2, rest of primes are odd. Therefore $p-1$ is an even number that can at least has 2 as a divisor.
For the second part of your questions; What you do is playing with the equations;
φ(n)=(p−1)(q−1)=pq−p−q+1=(n+1)−(p+q)
(n+1)−φ(n)=p+q
(n+1)−φ(n)−p=q
and n=pq to obtain this quadratic formula.
p2−(n+1−φ(n))p+n=0
For more details and an example see; Why is it important that phi(n) is kept a secret, in RSA?
I don't really understand the 2 questions below about T(n). I understand what theta means but I'm not sure about the answer for the questions. Can someone explain?
I thought that first one was false because T(2n/3) + 1 = Theta(log n) because
the constant 1 added doesn't make a difference
and log is closer to halving continuously but 2n/3 is not
I thought that second one was true because T(n/2) + n = Theta(n * log n) because
the linear "n *" in Theta represents the "+n" in T(n/2) + n
the "n/2" represents the log n in Theta...
The first is Θ(log n).
Intuitively, when you multiply n by a constant factor, T(n) increases by a constant amount.
Example: T(n) = log(n)/log(3/2)
The second is Θ(n).
Intuitively, when you multiply n by a constant factor, T(n) increases by an amount proportional to n.
Example: T(n) = 2n
I'm trying to calculate the big-O for Worst/Best/Average case of QuickSort using recurrence relations. My understanding is that the efficiency of your implementation is depends on how good the partition function is.
Worst Case: pivot always leaves one side empty
T(N) = N + T(N-1) + T(1)
T(N) = N + T(N-1)
T(N) ~ N2/2 => O(n^2)
Best Case: pivot divides elements equally
T(N) = N + T(N/2) + T(N/2)
T(N) = N + 2T(N/2) [Master Theorem]
T(N) ~ Nlog(N) => O(nlogn)
Average Case: This is where I'm confused how to represent the recurrence relation or how to approach it in general.
I know the average case big-O for Quicksort is O(nlogn) I'm just unsure how to derive it.
When you pick the pivot, the worst you can do is 0 | n and the best you can do is n/2 | n/2. The average case will find you getting a split of something more like n/4 | 3n/4, assuming uniform randomness. Plug that in and you get O(nlogn) once constants are eliminated.
How can I perform
x mod y (e.g. 89^3 mod 3127)
on this calculator?
I got Cryptography exam tomorrow and I can't figure out how to do the mod part on the calc that I have..
This is the encrypting part of RSA algorithm.
Any ideas?
I doubt your calculator has a modulus function. Here's a decent algorithm that works:
Compute 89^3 = 704 969. Write this down or store the result somewhere.
Now reduce modulo n. To do this, compute result / modulus and ignore the decimal, e.g. 704 969 / 3127 ≈ 225.
Multiply that number by the modulus and subtract it from the original result, e.g. 704 969 - 225*3127 = 1394.
If the original exponentiation is so large that it overflows your calculator, you can compute a smaller exponent and do the above reduction modulo n multiple times. For example, if you're asking to compute 89^10, you can instead compute 89^5, reduce that modulo n, square that result to get 89^10, and reduce the squared value modulo n as well.
A key point is that at pretty much any point in the computation process, you can reduce the value modulo n and still arrive at the same figure. Your professor may throw a curveball at you like this - or they may not. Still, better to be prepared.
I have polynomials of nontrivial degree (4+) and need to robustly and efficiently determine whether or not they have a root in the interval [0,T]. The precise location or number of roots don't concern me, I just need to know if there is at least one.
Right now I'm using interval arithmetic as a quick check to see if I can prove that no roots can exist. If I can't, I'm using Jenkins-Traub to solve for all of the polynomial roots. This is obviously inefficient since it's checking for all real roots and finding their exact positions, information I don't end up needing.
Is there a standard algorithm I should be using? If not, are there any other efficient checks I could do before doing a full Jenkins-Traub solve for all roots?
For example, one optimization I could do is to check if my polynomial f(t) has the same sign at 0 and T. If not, there is obviously a root in the interval. If so, I can solve for the roots of f'(t) and evaluate f at all roots of f' in the interval [0,T]. f(t) has no root in that interval if and only if all of these evaluations have the same sign as f(0) and f(T). This reduces the degree of the polynomial I have to root-find by one. Not a huge optimization, but perhaps better than nothing.
Sturm's theorem lets you calculate the number of real roots in the range (a, b). Given the number of roots, you know if there is at least one. From the bottom half of page 4 of this paper:
Let f(x) be a real polynomial. Denote it by f0(x) and its derivative f′(x) by f1(x). Proceed as in Euclid's algorithm to find
f0(x) = q1(x) · f1(x) − f2(x),
f1(x) = q2(x) · f2(x) − f3(x),
.
.
.
fk−2(x) = qk−1(x) · fk−1(x) − fk,
where fk is a constant, and for 1 ≤ i ≤ k, fi(x) is of degree lower than that of fi−1(x). The signs of the remainders are negated from those in the Euclid algorithm.
Note that the last non-vanishing remainder fk (or fk−1 when fk = 0) is a greatest common
divisor of f(x) and f′(x). The sequence f0, f1,. . ., fk (or fk−1 when fk = 0) is called a Sturm sequence for the polynomial f.
Theorem 1 (Sturm's Theorem) The number of distinct real zeros of a polynomial f(x) with
real coefficients in (a, b) is equal to the excess of the number of changes of sign in the sequence f0(a), ..., fk−1(a), fk over the number of changes of sign in the sequence f0(b), ..., fk−1(b), fk.
You could certainly do binary search on your interval arithmetic. Start with [0,T] and substitute it into your polynomial. If the result interval does not contain 0, you're done. If it does, divide the interval in 2 and recurse on each half. This scheme will find the approximate location of each root pretty quickly.
If you eventually get 4 separate intervals with a root, you know you are done. Otherwise, I think you need to get to intervals [x,y] where f'([x,y]) does not contain zero, meaning that the function is monotonically increasing or decreasing and hence contains at most one zero. Double roots might present a problem, I'd have to think more about that.
Edit: if you suspect a multiple root, find roots of f' using the same procedure.
Use Descartes rule of signs to glean some information. Just count the number of sign changes in the coefficients. This gives you an upper bound on the number of positive real roots. Consider the polynomial P.
P = 131.1 - 73.1*x + 52.425*x^2 - 62.875*x^3 - 69.225*x^4 + 11.225*x^5 + 9.45*x^6 + x^7
In fact, I've constructed P to have a simple list of roots. They are...
{-6, -4.75, -2, 1, 2.3, -i, +i}
Can we determine if there is a root in the interval [0,3]? Note that there is no sign change in the value of P at the endpoints.
P(0) = 131.1
P(3) = 4882.5
How many sign changes are there in the coefficients of P? There are 4 sign changes, so there may be as many as 4 positive roots.
But, now substitute x+3 for x into P. Thus
Q(x) = P(x+3) = ...
4882.5 + 14494.75*x + 15363.9*x^2 + 8054.675*x^3 + 2319.9*x^4 + 370.325*x^5 + 30.45*x^6 + x^7
See that Q(x) has NO sign changes in the coefficients. All of the coefficients are positive values. Therefore there can be no roots larger than 3.
So there MAY be either 2 or 4 roots in the interval [0,3].
At least this tells you whether to bother looking at all. Of course, if the function has opposite signs on each end of the interval, we know there are an odd number of roots in that interval.
It's not that efficient, but is quite reliable. You can construct the polynomial's Companion Matrix (A sparse matrix whose eigenvalues are the polynomial's roots).
There are efficient eigenvalue algorithms that can find eigenvalues in a given interval. One of them is the inverse iteration (Can find eigenvalues closest to some input value. Just give the middle point of the interval as the above value).
If the value f(0)*f(t)<=0 then you are guaranteed to have a root. Otherwise you can start splitting the domain into two parts (bisection) and check the values in the ends until you are confident there is no root in that segment.
if f(0)*f(t)>0 you either have no, two, four, .. roots. Your limit is the polynomial order. if f(0)*f(t)<0 you may have one, three, five, .. roots.