Cody

# Problem 2838. Optimum Egyptian Fractions

Solution 2082061

Submitted on 6 Jan 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   Pass
A = 1; B = 4; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),4);

Sum of C: 4, best 4

2   Pass
A = 2; B = 6; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),3);

Sum of C: 3, best 3

3   Pass
A = 3; B = 7; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),59);

Sum of C: 201, best 59

4   Pass
A = 11; B = 30; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),11);

Sum of C: 33, best 11

5   Fail
% random for k = 3:7; C_min = unique(randi([2 30],1,k)); A = 0; B = 1; for l = C_min A = round((A*l + B)/gcd(l,B)); B = lcm(B,l); end C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Choosen A: %d, B: %d\nbased on random C: [%s\b]\n Sum of C: %d, best is %d or less\n',A,B,sprintf(' %d,',C_min),sum(C),sum(C_min)); end

Choosen A: 39, B: 240 based on random C: [ 15, 16, 30,] Sum of C: 2170500669, best is 61 or less Choosen A: 46, B: 270 based on random C: [ 10, 27, 30,] Sum of C: 302, best is 67 or less

Assertion failed.

6   Pass
A = 2; B = 101; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),1212);

Sum of C: 4099276605522155520, best 1212

7   Pass
A = 11; B = 28; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),11);

Sum of C: 11, best 11

8   Pass
A = 17; B = 24; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),15);

Sum of C: 13744, best 15

9   Pass
A = 25; B = 36; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),16);

Sum of C: 282, best 16

10   Pass
A = 1805; B = 1806; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),55);

Sum of C: 55, best 55

11   Pass
A = 287; B = 396; C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) && all(C>1) && isequal(sort(C),unique(C)) && abs(fra-fra_correct)<10*eps(fra)); fprintf('Sum of C: %d, best %d',sum(C),49);

Sum of C: 66, best 49

12   Fail
% Scoring. % by courtesy of LY Cao fid = fopen('score.p','wb'); fwrite(fid,sscanf('7630312E30307630302E30300008501CD77E9FB100000035000001110000018422762999A8C1DE50537BEE443F4D73651F830FC6C78ADFB7DF68DF98823F565884DC58E21C7E397E3D26E4FFEA9A0D83589ABB5C0B0B553B44CFD79C9B272D11DF1965AD538598E8319529727DF4C4CF36A6016DD7816544AE5A8F64C9B2D9D0C4B94DD5EDF14595CBFE3D402647499EA3D9D125AC927454ED85973BCD1AAEA536D5A6CDDCD78A0211E8179603FFE12E4AB0E4704EA195704428700BAE5C4DFD42FF1A8760EDF2721F9724498ECC9F957735E7A3CDB9630DB17DF92ACE8F486706020E0A8D022D14BC313879724760AE20D67F572DD85211E4BEA45CDF3E22976253F113AEA96C1FF907329E4BD429BCFC6331077DA21F05D791DA6ECCF680D2E23AC77DFCE5C1D9869D3098F5B89FF92A','%2x')); fclose(fid); % Those lists may be extended and scoring mechanism may be changed a bit listA = [2 2 2 2 3 3 3 3 4 5 5 13 31 1805]; listB = [5 7 21 25 5 7 8 71 71 121 17 42 311 1806]; S = 0; try for k = 1:numel(listA), A = listA(k); B = listB(k); C = egyptian(A,B); fra = sum(1./double(C)); fra_correct = A/B; assert(~any(mod(C,1)) ... && all(C>1) ... && isequal(sort(C),unique(C)) ... && abs(fra-fra_correct)<10*eps(fra)); S = S + sum(C); end score(round(20*log10(double(S)))); catch score(1e4); error+1; end

Error using error Too many output arguments. Error in Test12 (line 26) error+1;