Cody

# Problem 1833. Usage of java.math : Add, Multiply, Pow

Solution 2549088

Submitted on 14 Jun 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
x=2; y=64; % power zstr=java_math(x,y,3); assert(strcmp(zstr,'18446744073709551616'),sprintf('zstr=%s\n',zstr))

select = 3 xBD1 = 2 xBD2 = 64 zstr = '66'

zstr=66

2   Pass

select = 1 xBD1 = 18446744073709551615 xBD2 = 3 zstr = '18446744073709551618'

3   Fail
x=2^53; % largest eps==1 double y=2^11; %Multiply zstr=java_math(x,y,2); assert(strcmp(zstr,'18446744073709551616'),sprintf('zstr=%s\n',zstr))

select = 2 xBD1 = 9007199254740992 xBD2 = 2048 zstr = '9007199254743040'

zstr=9007199254743040

4   Fail
x=2^53; % largest valid double y=2^12; % Multiply zstr=java_math(x,y,2); assert(strcmp(zstr,'36893488147419103232'),sprintf('zstr=%s\n',zstr))

select = 2 xBD1 = 9007199254740992 xBD2 = 4096 zstr = '9007199254745088'

zstr=9007199254745088

5   Pass
x=randi(10); y=randi(100); zstr=java_math(x,y,1); assert(strcmp(zstr,num2str(x+y)),sprintf('x=%2i y=%3i x+y=%5i zstr=%s\n',x,y,x+y,zstr))

select = 1 xBD1 = 9 xBD2 = 43 zstr = '52'

6   Fail
x=randi(10); y=randi(100); zstr=java_math(x,y,2); assert(strcmp(zstr,num2str(x*y)),sprintf('x=%2i y=%3i x*y=%5i zstr=%s\n',x,y,x*y,zstr))

select = 2 xBD1 = 1 xBD2 = 16 zstr = '17'

x= 1 y= 16 x*y= 16 zstr=17

7   Fail
x=randi(20); y=randi(5); zstr=java_math(x,y,3); assert(strcmp(zstr,num2str(x^y)),sprintf('x=%2i y=%3i x^y=%8i zstr=%s\n',x,y,x^y,zstr))

select = 3 xBD1 = 17 xBD2 = 2 zstr = '19'

x=17 y= 2 x^y= 289 zstr=19