Message Boards Message Boards

0
|
2707 Views
|
3 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Divisibility of numbers [Mathematica]

Posted 10 years ago

I need to find 2-digit numbers that are divisible by the sum of their digits. I think about 'select' and 'mod', but I don't know how do this.

POSTED BY: Artur Smura
3 Replies

Hi Artur,

something like this?

Select[ Range[10, 99], Divisible[#, Total[IntegerDigits[#]]] &]

which gives:

{10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90}

Cheers,

Marco

POSTED BY: Marco Thiel

Marco's way is better, but:

10a+b/.Solve[(10a+b)/k==a+b&&1<=a<=9&&0<=b<=9,{a,b,k},Integers]         

Out[3]= {10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90}
POSTED BY: Daniel Lichtblau
Posted 10 years ago

this is it! Thanks

POSTED BY: Artur Smura
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract