Redian新闻
>
问一道 Interviewstreet 上的题 (JAVA)
avatar
问一道 Interviewstreet 上的题 (JAVA)# JobHunting - 待字闺中
N*S
1
看来找工作不练练算法不行啊....
Using Java:
https://www.interviewstreet.com/challenges/dashboard/#problem/4f7272a8b9d15
There is one friendly number and N unfriendly numbers. We want to find how
many numbers are there which exactly divide the friendly number, but does
not divide any of the unfriendly numbers.
Input Format:
The first line of input contains two numbers N and K seperated by spaces. N
is the number of unfriendly numbers, K is the friendly number.
The second line of input contains N space separated unfriendly numbers.
Output Format:
Output the answer in a single line.
Constraints:
1 <= N <= 10^6
1 <= K <= 10^13
1 <= unfriendly numbers <= 10^18
Sample Input:
8 16
2 5 7 4 3 8 3 18
Sample Output:
1
Explanation :
Divisors of the given friendly number 16, are { 1, 2, 4, 8, 16 } and the
unfriendly numbers are {2, 5, 7, 4, 3, 8, 3, 18}. Now 1 divides all
unfriendly numbers, 2 divide 2, 4 divide 4, 8 divide 8 but 16 divides none
of them. So only one number exists which divide the friendly number but does
not divide any of the unfriendly numbers. So the answer is 1.
avatar
c*t
2
这个题除了brute force, O(N^2),还有别的解法吗?

4f7272a8b9d15
N

【在 N*********S 的大作中提到】
: 看来找工作不练练算法不行啊....
: Using Java:
: https://www.interviewstreet.com/challenges/dashboard/#problem/4f7272a8b9d15
: There is one friendly number and N unfriendly numbers. We want to find how
: many numbers are there which exactly divide the friendly number, but does
: not divide any of the unfriendly numbers.
: Input Format:
: The first line of input contains two numbers N and K seperated by spaces. N
: is the number of unfriendly numbers, K is the friendly number.
: The second line of input contains N space separated unfriendly numbers.

avatar
t*g
3
同文,如果是brute force是不是复杂度应该是O(N*K^0.5)?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。