由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Amazon interview question.
相关主题
divide two integersPalantir新鲜面经
一道题问个算time complexity的问题
请教一个phone interview 问题Google onsite一题
facebook on site后多久给消息啊Amazon电面两题
两个Amazon面试题Yelp电面小问题汇总
C++里做hashset的time complexity是多少?请教背包问题。
【什么时候需要做heap, 什么时候需要做BST】说一个我自己用的题吧
Ask a amazon question from careercup.攒rp整理面试题(1)string match/text search
相关话题的讨论汇总
话题: logn话题: primary话题: amazon话题: complexity话题: sqrt
进入JobHunting版参与讨论
1 (共1页)
B*******1
发帖数: 2454
1
what is the time complexity of finding the number of devisors of a number?
b****y
发帖数: 93
2
0(logn)?
S**I
发帖数: 15689
3
O(sqrt(n))

【在 B*******1 的大作中提到】
: what is the time complexity of finding the number of devisors of a number?
a********1
发帖数: 750
4
sqrt(n)吧,只能一个一个的试

【在 B*******1 的大作中提到】
: what is the time complexity of finding the number of devisors of a number?
r*******g
发帖数: 1335
5
I guess it is o(logn).
First, try to get N=a1^m1*a2^m2....which can be done iteratively.
Each step, try to find if it still contains primaries from a1 to ak, if yes,
increase m1 to mk, if not, try to find the next primary a_k+1. Since we
already maintained all the smaller primaries a1 to ak, we can just test the
next primary, and so on.
Then the result will be (m1+1)*(m2+1).....

【在 S**I 的大作中提到】
: O(sqrt(n))
S**I
发帖数: 15689
6
You're assuming all the prime numbers are already known.

yes,
the

【在 r*******g 的大作中提到】
: I guess it is o(logn).
: First, try to get N=a1^m1*a2^m2....which can be done iteratively.
: Each step, try to find if it still contains primaries from a1 to ak, if yes,
: increase m1 to mk, if not, try to find the next primary a_k+1. Since we
: already maintained all the smaller primaries a1 to ak, we can just test the
: next primary, and so on.
: Then the result will be (m1+1)*(m2+1).....

s**x
发帖数: 405
7
This must be way higher than O(logn).
Consider an extremely large number N. Primality test alone takes O((logn)^4)
. If N is composite and only has large factors, then you're screwed.
r*******g
发帖数: 1335
8
where did you get this O((logn)^4)?
testing whether primary might be an open problem. Even if it takes O((logn)^
4), that means after O((logn)^4) it is still primary, then, we already
ignore those small primaries which are not its divisor. We can still try to
find its primary divisor first. In this way, it is still quicker than
directly test sqrt(n) numbers.
In reality, primary numbers are known for some range. Find the primary
divisors should work fast. Otherwise, testing whether it is primary itself
is hard problem.

4)

【在 s**x 的大作中提到】
: This must be way higher than O(logn).
: Consider an extremely large number N. Primality test alone takes O((logn)^4)
: . If N is composite and only has large factors, then you're screwed.

s**x
发帖数: 405
9
Please read this:
http://en.wikipedia.org/wiki/Primality_test
This is deterministic polynomial time.
Best known deterministic algorithm is AKS primality test in O((logn)^7.5).
Best practical probabilitic algorithm is Miller-Rabin in O((logn)^4)
S**I
发帖数: 15689
10
Primality test is not a hard problem, as the wikipedia link provided by shyx
shows. However, what's the complexity of finding all prime numbers smaller than sqrt(n)?

)^
to

【在 r*******g 的大作中提到】
: where did you get this O((logn)^4)?
: testing whether primary might be an open problem. Even if it takes O((logn)^
: 4), that means after O((logn)^4) it is still primary, then, we already
: ignore those small primaries which are not its divisor. We can still try to
: find its primary divisor first. In this way, it is still quicker than
: directly test sqrt(n) numbers.
: In reality, primary numbers are known for some range. Find the primary
: divisors should work fast. Otherwise, testing whether it is primary itself
: is hard problem.
:

s**x
发帖数: 405
11
Well you can always use GNFS http://en.wikipedia.org/wiki/GNFS to completely factor N, then it is trivial to know the number of divisors.
Complexity is O((exp((64/9)^(1/3)+o(1))*((logn)^(1/3))*((loglogn)^(2/3))
It is not clear to me if there is an asymptotically faster method that does
not require factorization.
k****n
发帖数: 369
12
no way... there is no efficient algorithm for big integer factorization

yes,
the

【在 r*******g 的大作中提到】
: I guess it is o(logn).
: First, try to get N=a1^m1*a2^m2....which can be done iteratively.
: Each step, try to find if it still contains primaries from a1 to ak, if yes,
: increase m1 to mk, if not, try to find the next primary a_k+1. Since we
: already maintained all the smaller primaries a1 to ak, we can just test the
: next primary, and so on.
: Then the result will be (m1+1)*(m2+1).....

p*****w
发帖数: 429
13
how did you get this?
for example, 16
sqrt(16) = 4
you only search 0 to 4?
I think it should be O(N)

【在 S**I 的大作中提到】
: O(sqrt(n))
S**I
发帖数: 15689
14
think again :)

【在 p*****w 的大作中提到】
: how did you get this?
: for example, 16
: sqrt(16) = 4
: you only search 0 to 4?
: I think it should be O(N)

1 (共1页)
进入JobHunting版参与讨论
相关主题
攒rp整理面试题(1)string match/text search两个Amazon面试题
贴一下我google第一轮店面的题目C++里做hashset的time complexity是多少?
Rabin-Karp算法对不定长的query set怎么办?【什么时候需要做heap, 什么时候需要做BST】
Visiting Research Programmer(ZZ)Ask a amazon question from careercup.
divide two integersPalantir新鲜面经
一道题问个算time complexity的问题
请教一个phone interview 问题Google onsite一题
facebook on site后多久给消息啊Amazon电面两题
相关话题的讨论汇总
话题: logn话题: primary话题: amazon话题: complexity话题: sqrt