Cody

# Problem 3003. Mobius function

Solution 590592

Submitted on 3 Mar 2015 by J.R.! Menzinger
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
%% n = 1:5; arr_corr = [1, -1, -1, 0, -1]; assert(isequal(mobius_func_seq(n),arr_corr))

ans = 1 -1 -1 0 -1

2   Pass
%% n = 1:10; arr_corr = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1]; assert(isequal(mobius_func_seq(n),arr_corr))

ans = 1 -1 -1 0 -1 1 -1 0 0 1

3   Pass
%% n = 3:7; arr_corr = [-1, 0, -1, 1, -1]; assert(isequal(mobius_func_seq(n),arr_corr))

ans = -1 0 -1 1 -1

4   Pass
%% n = 20:30; arr_corr = [0 1 1 -1 0 0 1 0 0 -1 -1]; assert(isequal(mobius_func_seq(n),arr_corr))

ans = 0 1 1 -1 0 0 1 0 0 -1 -1

5   Pass
%% n = 1:77; arr_corr = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, 1]; assert(isequal(mobius_func_seq(n),arr_corr))

ans = Columns 1 through 16 1 -1 -1 0 -1 1 -1 0 0 1 -1 0 -1 1 1 0 Columns 17 through 32 -1 0 -1 0 1 1 -1 0 0 1 0 0 -1 -1 -1 0 Columns 33 through 48 1 1 1 0 -1 1 1 0 -1 -1 -1 0 0 1 -1 0 Columns 49 through 64 0 0 1 0 -1 0 1 0 1 1 -1 0 -1 1 0 0 Columns 65 through 77 1 -1 -1 0 1 -1 -1 0 -1 1 0 0 1

6   Pass
%% prevents cheating i1 = randi(20,1); n = i1:(i1+randi(25,1)); arr_tot = [1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, 1]; arr_corr = arr_tot(n); assert(isequal(mobius_func_seq(n),arr_corr))

ans = Columns 1 through 16 0 1 -1 0 -1 1 1 0 -1 0 -1 0 1 1 -1 0 Columns 17 through 23 0 1 0 0 -1 -1 -1