Cody

# Problem 656. Calculate Euler's phi function

Solution 2723781

Submitted on 21 Jul 2020 by Jerry Wright
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))

n = 1 uf = 1 phi = 1 n = 2 uf = 2 phi = 1 1 n = 3 uf = 3 phi = 1 1 2 n = 4 uf = 2 phi = 1 1 2 2 n = 5 uf = 5 phi = 1 1 2 2 4 n = 6 uf = 2 3 phi = 1 1 2 2 4 2 n = 7 uf = 7 phi = 1 1 2 2 4 2 6 n = 8 uf = 2 phi = 1 1 2 2 4 2 6 4 n = 9 uf = 3 phi = 1 1 2 2 4 2 6 4 6 n = 10 uf = 2 5 phi = 1 1 2 2 4 2 6 4 6 4 n = 11 uf = 11 phi = 1 1 2 2 4 2 6 4 6 4 10 n = 12 uf = 2 3 phi = 1 1 2 2 4 2 6 4 6 4 10 4 n = 13 uf = 13 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 n = 14 uf = 2 7 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 n = 15 uf = 3 5 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 n = 16 uf = 2 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 n = 17 uf = 17 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 n = 18 uf = 2 3 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 n = 19 uf = 19 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 n = 20 uf = 2 5 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 8 n = 21 uf = 3 7 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 8 12 n = 22 uf = 2 11 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 8 12 10 n = 23 uf = 23 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 8 12 10 22 n = 24 uf = 2 3 phi = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 8 12 10 22 8 n = 25 uf = 5 phi = 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 n = 26 uf = 2 13 phi = 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 n = 27 uf = 3 phi = 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 n = 28 uf = 2 7 phi = 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 n = 29 uf = 29 phi = 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 n = 30 uf = 2 3 5 phi = 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 n = 31 uf = 31 phi = Columns 1 through 30 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 Column 31 30 n = 32 uf = 2 phi = Columns 1 through 30 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 Columns 31 through 32 30 16 n = 33 uf = 3 11 phi = Columns 1 through 30 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 Columns 31 through 33 30 16 20 n = 34 uf = 2 17 phi = Columns 1 through 30 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 Columns 31 through 34 30 16 20 16 n = 35 uf = 5 7 phi = Columns 1 through 30 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 Columns 31 through 35 30 16 20 16 24 n = 36 uf = 2 3 phi = Columns 1 through 30 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 Columns 31 through 36 30 16 20 16 24 12 n = 37 uf = 37 phi = Columns 1 through 30 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 Columns 31 through 37 30 16 20 16 24 12 36 n = 38 uf = 2 19 phi = Columns 1 through 30 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 Columns 31 through 38 30 16 20 16 24 12 36 18 n = 39 uf = 3 13 phi = Columns 1 through 30 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 Columns 31 through 39 30 16 20 16 24 12 36 18 24 n = 40 uf = 2 5 phi = Columns 1 through 30 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 Columns 31 through 40 30 16 20 16 24 12 36 18 24 16 n = 41 uf = 41 phi = Columns 1 through 30 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 Columns 31 through 41 30 16 20 16 24 12 36 18 24 16 40 n = 42 uf = 2 3 7 phi = Columns 1 through 30 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 Columns 31 through 42 30 16 20 16 24 12 36 18 24 16 40 12 n = 43 uf = 43 phi = Columns 1 through 30 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 Columns 31 through 43 30 16 20 16 24 12 36 18 24 16 40 12 42 n = 44 uf = 2 11 phi = Columns 1 through 30 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 Columns 31 through 44 30 16 20 16 24 12 36 18 24 16 40 12 42 20 n = 45 uf = 3 5 phi = Columns 1 through 30 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 Columns 31 through 45 30 16 20 16 24 12 36 18 24 16 40 12 42 20 24 n = 46 uf = 2 23 phi = Columns 1 through 30 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 Columns 31 through 46 30 16 20 16 24 12 36 18 24 16 40 12 42 20 24 22 n = 47 uf = 47 phi = Columns 1 through 30 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 Columns 31 through 47 30 16 20 16 24 12 36 18 24 16 40 12 42 20 24 22 46 n = 48 uf = 2 3 phi = Columns 1 through 30 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 Columns 31 through 48 30 16 20 16 24 12 36 18 24 16 40 12 42 20 24 22 46 16 n = ...

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

n = 32767 uf = 7 31 151 phi = 27000 n = 65535 uf = 3 5 17 257 phi = 32768

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

n = 2.1475e+09 uf = 2.1475e+09 phi = 2.1475e+09 n = 4.2950e+09 uf = 3 5 17 257 65537 phi = 2.1475e+09