UVa 10929

From Algorithmist
Jump to navigation Jump to search

10929 - You can say 11[edit]

Summary[edit]

Determine if a large positive number is a multiple if 11.

Explanation[edit]

If ABCDEFG is multiple of 11, then A-B+C-D+E-F+G... is also divisible by 11. Otherwise ABCDEFG isn't a multiple of 11.

Another method (similar to long-division on pen and paper) is to read digits one-by-one, and apply the modulus; this will work on any arbitrary number, while using primitive types. A number N is divisible by 11 if the final digit results in no remainder.

Gotchas[edit]

Numbers can have leading zeros.

Solutions[edit]

Input[edit]

112233
30800
2937
323455693
5038297
112234
0

Output[edit]

112233 is a multiple of 11.
30800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
112234 is not a multiple of 11.