Skip to content

Instantly share code, notes, and snippets.

@ik11235
Created February 18, 2015 03:46
Show Gist options
  • Save ik11235/72cafa895147f3898889 to your computer and use it in GitHub Desktop.
Save ik11235/72cafa895147f3898889 to your computer and use it in GitHub Desktop.
class TaroJiroDividing {
public:
int getNumber(int A, int B) {
set<int> hash;
hash.insert(A);
for(;A%2==0;)
{
A/=2;
hash.insert(A);
}
int cnt=0;
if(hash.count(B)!=0)
cnt++;
for(;B%2==0;)
{
B/=2;
if(hash.count(B)!=0)
cnt++;
}
return cnt;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment