Cody

Problem 42455. Divisible by n, prime divisors - 11, 13, 17, & 19

Created by goc3 in Community

Divisibility checks against prime numbers can all be accomplished with the same routine, applied recursively, consisting of add or subtract x times the last digit to or from the remaining number. For example, for 13, add four times the last digit to the rest:

  • 2392: 239 + 4*2 = 247: 24 + 4*7 = 52: 5 + 4*2 = 13 -> 2392 is divisible by 13.

For 17, subtract five times the last digit from the rest:

  • 3281: 328 - 5*1 = 323: 32 - 5*3 = 17 -> 3281 is divisible by 17.

For 19, add two times the last digit to the rest:

  • 16863: 1686 + 2*3 = 1692: 169 + 2*2 = 173: 17 + 2*3 = 23: 2 + 2*3 = 8 -> 16863 is not divisible by 19.

And, for 11, subtract the last digit from the rest:

  • 269830: 26983 - 0 = 26983: 2698 - 3 = 2695: 269 - 5 = 264: 26 - 4 = 22: 2 - 2 = 0 -> 269830 is divisible by 11.

Write a function to return a true-false vector for the prime numbers in the 11:20 range ([11 13 17 19]) based on a number supplied as a string.

Restrictions on Java, mod, ceil, round, and floor are still in effect.

Previous problem: Divisible by n, prime divisors (including powers). Next problem: Divisible by n, prime divisors from 20 to 200.

Solution Stats

43.21% Correct | 56.79% Incorrect
Last solution submitted on Nov 23, 2018

Problem Comments

Recent Solvers27

Suggested Problems

More from this Author161

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!