由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一个L的题目
相关主题
问几道面试题问一道算法题largest subsequence sum <= max
Amazon两轮电面Ask a google interview question(2)
一道Facebook题如何避免溢出急问一个Java Hashset的 考试题。
问道面试题A Google Problem (2)
一道program challenge的题感觉这是一道经典题
FB这几个题怎么做回报本版 V家面经
a very difficult interview question问一道题(3)
问道看到的面试题请教一个面试题
相关话题的讨论汇总
话题: unsigned话题: ret话题: result话题: val话题: sum
进入JobHunting版参与讨论
1 (共1页)
g********r
发帖数: 89
1
Returns the next integer a in the arithmetic sequence of integers where
* a = m^n, m > 1 n > 1, and m and n are both integers
* Thus, the first few outputs will be 4, 8, 9, 16, 25, 27, 32, 36, etc
s*******g
发帖数: 170
2
我的一个解法:
unsigned long calc(unsigned m, unsigned n) {
if(m < 2 || m < 2) return 0;
unsigned long ret = m;
for(unsigned i = 1; i < n; ++i)
ret *= m;
return ret;
}
unsigned findNext2(unsigned val) {
unsigned long ret = INT_MAX;
unsigned smallest = 0;
unsigned sum = 4;
while(smallest <= val) {
unsigned n = 2;
for(unsigned i = n; i <= sum-2; ++i) {
unsigned long result = calc(sum-i, i);
if(i == 2) smallest = result;
if(result > val) ret = min(ret, result);
if(result > val) break;
}
for(unsigned i = n; i <= sum-2; ++i) {
unsigned long result = calc(i, sum-i);
if(result > val) ret = min(ret, result);
if(result > val) break;
}
++sum;
}
return ret;
}

【在 g********r 的大作中提到】
: Returns the next integer a in the arithmetic sequence of integers where
: * a = m^n, m > 1 n > 1, and m and n are both integers
: * Thus, the first few outputs will be 4, 8, 9, 16, 25, 27, 32, 36, etc

r****7
发帖数: 2282
3
应该用binary search来解吧

【在 s*******g 的大作中提到】
: 我的一个解法:
: unsigned long calc(unsigned m, unsigned n) {
: if(m < 2 || m < 2) return 0;
: unsigned long ret = m;
: for(unsigned i = 1; i < n; ++i)
: ret *= m;
: return ret;
: }
: unsigned findNext2(unsigned val) {
: unsigned long ret = INT_MAX;

z***b
发帖数: 127
1 (共1页)
进入JobHunting版参与讨论
相关主题
请教一个面试题一道program challenge的题
请教几个面试题FB这几个题怎么做
Linkedin这道题用非递归该怎么写啊?a very difficult interview question
问一道lyft design题,求大神!问道看到的面试题
问几道面试题问一道算法题largest subsequence sum <= max
Amazon两轮电面Ask a google interview question(2)
一道Facebook题如何避免溢出急问一个Java Hashset的 考试题。
问道面试题A Google Problem (2)
相关话题的讨论汇总
话题: unsigned话题: ret话题: result话题: val话题: sum