Cody

# Problem 656. Calculate Euler's phi function

Solution 194058

Submitted on 20 Jan 2013 by Khaled Hamed
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
%% vectorized 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))

``` ans = 1 ans = 1 1 ans = 1 1 2 ans = 1 1 2 2 ans = 1 1 2 2 4 ans = 1 1 2 2 4 2 ans = 1 1 2 2 4 2 6 ans = 1 1 2 2 4 2 6 4 ans = 1 1 2 2 4 2 6 4 6 ans = 1 1 2 2 4 2 6 4 6 4 ans = 1 1 2 2 4 2 6 4 6 4 10 ans = 1 1 2 2 4 2 6 4 6 4 10 4 ans = 1 1 2 2 4 2 6 4 6 4 10 4 12 ans = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 ans = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 ans = 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Column 17 16 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 18 16 6 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 19 16 6 18 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 20 16 6 18 8 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 21 16 6 18 8 12 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 22 16 6 18 8 12 10 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 23 16 6 18 8 12 10 22 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 24 16 6 18 8 12 10 22 8 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 25 16 6 18 8 12 10 22 8 20 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 26 16 6 18 8 12 10 22 8 20 12 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 27 16 6 18 8 12 10 22 8 20 12 18 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 28 16 6 18 8 12 10 22 8 20 12 18 12 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 29 16 6 18 8 12 10 22 8 20 12 18 12 28 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 30 16 6 18 8 12 10 22 8 20 12 18 12 28 8 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 31 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Column 33 20 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 34 20 16 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 35 20 16 24 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 36 20 16 24 12 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 37 20 16 24 12 36 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 38 20 16 24 12 36 18 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 39 20 16 24 12 36 18 24 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 40 20 16 24 12 36 18 24 16 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 41 20 16 24 12 36 18 24 16 40 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 42 20 16 24 12 36 18 24 16 40 12 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 43 20 16 24 12 36 18 24 16 40 12 42 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 44 20 16 24 12 36 18 24 16 40 12 42 20 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 45 20 16 24 12 36 18 24 16 40 12 42 20 24 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 46 20 16 24 12 36 18 24 16 40 12 42 20 24 22 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 47 20 16 24 12 36 18 24 16 40 12 42 20 24 22 46 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 48 20 16 24 12 36 18 24 16 40 12 42 20 24 22 46 16 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 48 20 16 24 12 36 18 24 16 40 12 42 20 24 22 46 16 Column 49 42 ans = Columns 1 through 16 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 Columns 17 through 32 16 6 18 8 12 10 22 8 20 12 18 12 28 8 30 16 Columns 33 through 48 20 16 24 12 36 18 ...```

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

``` ans = 27000 ans = 32768 ```

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

``` ans = 2.1475e+09 ans = 2.1475e+09 ```