Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // y = 2^0 * x * a0 + 2^1 * x * a1 + ... + 2 ^ k * x * ak
- int divide(unsigned x, unsigned y) {
- int result = 0;
- while (y >= x) {
- int power = 1;
- while ((x<<power) >= (x<<(power-1)) && (x<<power) <= y) {
- ++power;
- }
- result |= 1<<(power-1);
- y -= x<<(power-1);
- }
- return result;
- }
- int main() {
- int x = 4, y = 100;
- cout<<divide(x, y)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement