Cody

Problem 42508. Divisible by n, prime divisors from 20 to 200

Created by goc3 in Community

Pursuant to the previous problem (linked below), this problem requires a function that checks for divisibility of large numbers for any prime number from 20 to 200. Similar to the previous problem, these can all be checked using the same routine: add or subtract x times the last digit to or from the remaining number after removing that last digit. For example, for 127, the last-digit factor is -38:

  • 2048379: 204837 + -38*9 = 204495: 20449 + -38*5 = 20259: 2025 + -38*9 = 1683: 168 + -38*3 = 54 -> 2048379 is not divisible by 127 since 54 is not divisible by 127.
  • 4853940: 485394 + -38*0 = 485394: 48539 + -38*4 = 48387: 4838 + -38*7 = 4572: 457 + -38*2 = 381: 38 + -38*1 = 0 -> 4853940 is divisible by 127.

Your function will be provided with the prime number, n, and the number to check for divisibility as a string, n_str. Write a function that returns true or false for each prime number and candidate number pair. See the test suite for more examples. The template function will include arrays of all possible prime number in the given range in addition to a paired array with the associated factors.

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

Previous problem: Divisible by n, prime divisors - 11, 13, 17, & 19. Next problem: Divisible by n, Truncated-number Divisors.

Solution Stats

41.67% Correct | 58.33% Incorrect
Last solution submitted on Nov 23, 2018

Recent Solvers25

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!