由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - fast way to sove n*m or n/m using only "add" operation?
相关主题
a question about bits operationC++ 一小题
问一道算法题急问有没有面试过bloomberg的senior calculations programmer的?
Data Operations opportunityabout how to test a calculator program on computer
问一道fb的面试题目Bloomberg phone interview (intern)
一道难题c++ class default functions?
讨论下lc最新的那道hard题吧大家帮我看看我的recruiter是在帮我还是在玩我?
求助一道算法题, 在限定三个operation下使一个数变成1的最小操作数Divide a number by 3 without using *, /, +, -, % operators [转载]
这道题怎么做的?弱问一下,cracking the coding interview上有关bit manipulation的解释正确么
相关话题的讨论汇总
话题: add话题: way话题: digit话题: operation话题: sove
进入JobHunting版参与讨论
1 (共1页)
r******e
发帖数: 80
1
Given integer n and m, is there a fast way to calculate n*m or n/m using
only 'add' operation?
a straightforward way to calculate n*m and n/m is to add m times of n and
add multiple times of -m. Not sounds optimization enough. Any idea?
Thanks a lot.
l*****a
发帖数: 559
2
There exists logarithmic way to do this job.
int divide(int a,int b){
int res = 0;
int digit = 1;
while(b<<1<=a){
b = b<<1;
digit = digit<<1;
}
while(digit>0&&a>0){
if(a>=b){
res +=digit;
a-=b;
}
b>>=1;
digit>>=1;
}
return res;
}
i***1
发帖数: 95
3
awesome!

【在 l*****a 的大作中提到】
: There exists logarithmic way to do this job.
: int divide(int a,int b){
: int res = 0;
: int digit = 1;
: while(b<<1<=a){
: b = b<<1;
: digit = digit<<1;
: }
: while(digit>0&&a>0){
: if(a>=b){

r******e
发帖数: 80
4
看了半天, 不明白为什么。 楼主能不能把原理解释一下? 非常感谢
1 (共1页)
进入JobHunting版参与讨论
相关主题
弱问一下,cracking the coding interview上有关bit manipulation的解释正确么一道难题
Amazon China Operation Manager Position讨论下lc最新的那道hard题吧
我公司在招 DevOps Sr. Operations Software Engineer求助一道算法题, 在限定三个operation下使一个数变成1的最小操作数
Amazon team match的问题这道题怎么做的?
a question about bits operationC++ 一小题
问一道算法题急问有没有面试过bloomberg的senior calculations programmer的?
Data Operations opportunityabout how to test a calculator program on computer
问一道fb的面试题目Bloomberg phone interview (intern)
相关话题的讨论汇总
话题: add话题: way话题: digit话题: operation话题: sove