Cody

Problem 656. Calculate Euler's phi function

Solution 2898239

Submitted on 1 Sep 2020 by Schiefermüller Lukas
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
y_correct = [ 1, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, ... 4, 12, 6, 8, 8, 16, 6, 18, 8, 12, ... 10, 22, 8, 20, 12, 18, 12, 28, 8, ... 30, 16, 20, 16, 24, 12, 36, 18, 24, ... 16, 40, 12, 42, 20, 24, 22, 46, 16, ... 42, 20, 32, 24, 52, 18, 40, 24, 36, 28, ... 58, 16, 60, 30, 36, 32, 48, 20, 66, 32, ... 44, 24, 70, 24, 72, 36, 40, 36, 60, 24, ... 78, 32, 54, 40, 82, 24, 64, 42, 56, 40, ... 88, 24, 72, 44, 60, 46, 72, 32, 96, 42, 60]; assert(isequal(eulerphi(1:99),y_correct))

1 1 2 1 3 2 4 2 5 4 6 2 7 6 8 4 9 6 10 4 11 10 12 4 13 12 14 6 15 8 16 8 17 16 18 6 19 18 20 8 21 12 22 10 23 22 24 8 25 20 26 12 27 18 28 12 29 28 30 8 31 30 32 16 33 20 34 16 35 24 36 12 37 36 38 18 39 24 40 16 41 40 42 12 43 42 44 20 45 24 46 22 47 46 48 16 49 42 50 20 51 32 52 24 53 52 54 18 55 40 56 24 57 36 58 28 59 58 60 16 61 60 62 30 63 36 64 32 65 48 66 20 67 66 68 32 69 44 70 24 71 70 72 24 73 72 74 36 75 40 76 36 77 60 78 24 79 78 80 32 81 54 82 40 83 82 84 24 85 64 86 42 87 56 88 40 89 88 90 24 91 72 92 44 93 60 94 46 95 72 96 32 97 96 98 42 99 60

2   Pass
assert(isequal(eulerphi(double(intmax('int16'))), 27000)) assert(isequal(eulerphi(double(intmax('uint16'))),32768))

32767 27000 65535 32768

3   Pass
assert(isequal(eulerphi(double(intmax('int32'))), 2147483646)) assert(isequal(eulerphi(double(intmax('uint32'))),2147483648))

1.0e+09 * 2.1475 2.1475 1.0e+09 * 4.2950 2.1475

Suggested Problems

More from this Author1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!