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
Here's an equation:
d is the multiple inverse of 3 modulo K.
Assuming I have d, can I find K?
Also, K is not necessarily prime.
Thanks!
You know that
d*3 = 1 (mod K)
this means
d*3 = 1 + n*K
independently of K this however means
d*3 = 1 (mod n)
i.e. that d is the inverse of 3 modulo n too, thus the answer is in general not unique (actually you can use any divisor of nK as answer).
Related
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
suppose that we have a m*n matrix that each rows are in order. so, i only know that order of best algorithm for this problem is O(m(log m + log n)).
(It was a test question and result is this order)
but i don't know how this algorithm works
One idea can be like this.
If I ask you what is the rank of a given number x in the original matrix? How do you answer this question?
One answer can be:
Just binary search the first occurrence of x or greater element on each row. and then add the individual ranks.
int rank = 1;
for (int i = 0; i < m; ++i) {
rank += std::lower_bound(matrix[i].begin(), matrix[i].end(), x);
}
This can be done in O(m * log n) time(m binary searches on n sized arrays).
Now we just need to do a binary search on x(between 0 and INT_MAX or matrix[0][k]) to find the kth rank. Since INT_MAX is const, that will make the overall time complexity O(m * log n) theoretically. One optimization, which can be done use intelligent ranges in place of matrix[i].begin(), matrix[i].end().
PS: Still wondering the O(m*(log m + log n)) or O( m * (log mn)) solution.
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 5 years ago.
Improve this question
I'm currently reading about Big-Oh and the way to prove the statements.
However, I need a feedback or just direction for proving.
So, I want to prove that for all real numbers a and b,
if b > a and a > 1, then b^n not in O(a^n).
I want to prove by contradiction, since b>a. Let b^n be in O(a^n), then
by definition of Big-oh, there is a constant c and natural number n0, such
that b^n <= ca^n, for all n >= n0. Thus n > max(n0, c) which is
contradiction.
I'm little bit lost and my last sentence, and looking for some feedback if it's possible.
The conclusion follows pretty closely from the definitions you've given, so the proof is not much more than you're already written. You need to get:
b^n ∈ O(a^n) ⇒ ∃ c,n0 : (b/a)^n < c for all n > n0
and
b > a > 1 ⇒ (b/a) > 1, and (b/a)^n grows without bound.
If you actually want to construct a contradiction you can show that for any c > 0, you can choose n > log(c) / log(b/a)
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 9 years ago.
Improve this question
I am working on a histogram problem, and then I ran into the following math problem:
Given N numbers, where the value of each number is different, denoted as v1, v2, ..., vn, and the probability of selecting each number is p1, p2, ..., pn, respectively.
Now if I select K numbers based on the given probabilities, where K <= N, what is the expectation of the sum of those K numbers? Note that the selection is without replacement, so that the K numbers cannot involve duplicate numbers. I understand that if the selection is with replacement, the expectation of the sum of the K numbers equals K * E(V), where E(V) = v1*p1 + v2*p2 + ... + vn*p2.
Furthermore, what about the expectation of the variance of those K numbers?
This question is better formulated at here.
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 9 years ago.
Improve this question
This is my fibonacci generator:
package main
import "fmt"
func main() {
for i, j := 0, 1; j < 100; i, j = i+j,i {
fmt.Println(i)
}
}
It's working, but I don't know how can I improve it, I'd like more expert approaches about it, Thanks...
I assume you are talking about improving the time complexity (and not the code complexity).
Your solution computes the Fibonacci numbers in O(n) time. Interestingly, there exists an O(log n) solution as well.
The algorithm is simple enough: Find the nth power of matrix A using a Divide and Conquer approach and report (0,0)th element, where
A = |1 1 |
|1 0 |
The recursion being
A^n = A^(n/2) * A^(n/2)
Time complexity:
T(n) = T(n/2) + O(1) = O(logn)
If you think about it with a piece of paper, you'd find that the proof is simple and is based upon the principle of induction.
If you still need help, refer to this link
NOTE: Of course, the O(logn) time is true only if you want to find the nth Fibonacci number. If, however, you intend to print ALL of the n fib numbers, theoretically, you can not have a better time complexity than you already have.
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
Kind of a math question, but very programming related. Doing some Big-O problems and I have an algorithm where a for loop will run n times, where k = input size, n = max power of 4 where (k)/(4^n) >= 1. How can I represent max power of 4 where (k)/(4^n) >= 1 in one mathematic statement?
floor ( (log k)/(log 4) ).
Or something along those lines.
Mathematic statement: [log_4(k)]
Code: floor( log(k) / log(4) )
log base 4 of k? Can take the floor if you only care about integer n.
Taking (k)/(4^n) >= 1, multiply both sides by 4^n to get k >= 4^n, and then take the log base 4 (log_4) of both sides to get log_4 k >= n, or n <= log_4 k. (Equivalently, take log of both sides and get log k >= log(4^n), then note log(4^n) = n log(4), and divide to get (log k)/(log 4) >= n). Choose the largest integer n satisfying this inequality, which is floor(log_4 k).