Cody

Problem 2595. Polite numbers. Politeness.

Solution 704070

Submitted on 21 Jul 2015 by Tomasz
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
%% x = 1; y_correct = 0; assert(isequal(politeness(x),y_correct))

ans = 1 ans = 0

2   Pass
%% x = 2; y_correct = 0; assert(isequal(politeness(x),y_correct))

ans = 2 ans = 0

3   Pass
%% x = 3; y_correct = 1; assert(isequal(politeness(x),y_correct))

ans = 3 ans = 1

4   Pass
%% x = 7; y_correct = 1; assert(isequal(politeness(x),y_correct))

ans = 7 ans = 1

5   Pass
%% x = 9; y_correct = 2; assert(isequal(politeness(x),y_correct))

ans = 3 3 ans = 2

6   Pass
%% x = 15; y_correct = 3; assert(isequal(politeness(x),y_correct))

ans = 3 5 ans = 3

7   Pass
%% x = 18; y_correct = 2; assert(isequal(politeness(x),y_correct))

ans = 2 3 3 ans = 2

8   Pass
%% x = 21; y_correct = 3; assert(isequal(politeness(x),y_correct))

ans = 3 7 ans = 3

9   Pass
%% x = 1024; y_correct = 0; assert(isequal(politeness(x),y_correct))

ans = 2 2 2 2 2 2 2 2 2 2 ans = 0

10   Pass
%% x = 1025; y_correct = 5; assert(isequal(politeness(x),y_correct))

ans = 5 5 41 ans = 5

11   Pass
%% x = 25215; y_correct = 11; assert(isequal(politeness(x),y_correct))

ans = 3 5 41 41 ans = 11

12   Pass
%% x = 62; y_correct = 1; assert(isequal(politeness(x),y_correct))

ans = 2 31 ans = 1

13   Pass
%% x = 63; y_correct = 5; assert(isequal(politeness(x),y_correct))

ans = 3 3 7 ans = 5

14   Pass
%% x = 65; y_correct = 3; assert(isequal(politeness(x),y_correct))

ans = 5 13 ans = 3

15   Pass
%% % anti-lookup & clue nums=primes(200); pattern=[1 nums([false ~randi([0 25],1,45)])]; x=prod(pattern)*2^randi([0 5]); y_correct=2^numel(pattern)/2-1; assert(isequal(politeness(x),y_correct))

ans = 2 2 2 43 163 181 ans = 7

16   Pass
%% for k=randi(2e4,1,20) assert(isequal(politeness(k*(k-1))+1,(politeness(k)+1)*(politeness(k-1)+1))) end

ans = 2 2 2 3 7 11 43 73 ans = 31 ans = 3 11 73 ans = 7 ans = 2 2 2 7 43 ans = 3 ans = 2 3 3 3 5 41 43 653 ans = 63 ans = 3 3 3 653 ans = 7 ans = 2 5 41 43 ans = 7 ans = 2 3 439 2633 ans = 7 ans = 2 3 439 ans = 3 ans = 2633 ans = 1 ans = 2 2 3 13 181 3137 ans = 15 ans = 2 2 13 181 ans = 3 ans = 3 3137 ans = 3 ans = 2 2 2 2 2 2 2 3 3 11 19 23 29 ans = 47 ans = 19 23 29 ans = 7 ans = 2 2 2 2 2 2 2 3 3 11 ans = 5 ans = 2 2 3 7 23 41 4951 ans = 31 ans = 2 2 4951 ans = 1 ans = 3 7 23 41 ans = 15 ans = 2 5 1493 3733 ans = 7 ans = 2 3733 ans = 1 ans = 5 1493 ans = 3 ans = 2 3 5 17 67 3797 ans = 31 ans = 3 3797 ans = 3 ans = 2 5 17 67 ans = 7 ans = 2 3 5 5 43 179 ans = 23 ans = 5 5 43 ans = 5 ans = 2 3 179 ans = 3 ans = 2 3 5641 8461 ans = 7 ans = 3 5641 ans = 3 ans = 2 8461 ans = 1 ans = 2 5 13 73 9491 ans = 15 ans = 9491 ans = 1 ans = 2 5 13 73 ans = 7 ans = 2 29 643 9323 ans = 7 ans = 29 643 ans = 3 ans = 2 9323 ans = 1 ans = 2 3 5 19 197 1123 ans = 31 ans = 2 5 1123 ans = 3 ans = 3 19 197 ans = 7 ans = 2 3 19 311 8863 ans = 15 ans = 3 19 311 ans = 7 ans = 2 8863 ans = 1 ans = 2 3 23 109 3761 ans = 15 ans = 2 3761 ans = 1 ans = 3 23 109 ans = 7 ans = 2 2 3 3 7 11 127 449 ans = 47 ans = 3 3 11 127 ans = 11 ans = 2 2 7 449 ans = 3 ans = 2 2 2 2 2 2 2 3 5 7 23 701 ans = 31 ans = 3 7 701 ans = 7 ans = 2 2 2 2 2 2 2 5 23 ans = 3 ans = 2 3 3 5 7 17 29 43 ans = 95 ans = 5 17 43 ans = 7 ans = 2 3 3 7 29 ans = 11 ans = 2 23 151 6947 ans = 7 ans = 6947 ans = 1 ans = 2 23 151 ans = 3 ans = 2 2 13 17 17 89 ans = 11 ans = 13 89 ans = 3 ans = 2 2 17 17 ans = 2

Suggested Problems

More from this Author41

Community Treasure Hunt

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

Start Hunting!