The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+1 vote
65 views

The below question is based on the following program. In the program, we assume that integer division returns only the quotient. For example 7/3 returns 2 since 2 is the quotient and 1 is the remainder.

mystery(a,b){
        if (b == 0) return a;
        if (a < b) return mystery(b,a);
        if (eo(a,b) == 0){
             return(2*mystery(a/2,b/2));
    }
    if (eo(a,b) == 1){
        return(mystery(a,b/2));
    }
    if (eo(a,b) == 2){
        return(mystery(a/2,b));
    }
    if (eo(a,b) == 3){
        return (mystery((a-b)/2,b));
    }
}
eo(a,b){
if ((a/2)*2 == a and (b/2)*2 == b) return 0; end;
if ((a/2)*2 < a and (b/2)*2 == b) return 1; end;
if ((a/2)*2 == a and (b/2)*2 < b) return 2; end;
return 3;
}

$mystery(75,210)$ returns

  1. 2
  2. 6
  3. 10
  4. 15
in Algorithms by Veteran (98.3k points) | 65 views

1 Answer

+1 vote
D) 15
by Junior (595 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,807 questions
54,713 answers
189,263 comments
79,709 users