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

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

40.1% Correct | 59.9% Incorrect
Last Solution submitted on Jun 02, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers66

Suggested Problems

More from this Author139

Community Treasure Hunt

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

Start Hunting!