No tags yet

No tag edit access

Time limit per test: 1.5 second(s)

Memory limit: 262144 kilobytes

Memory limit: 262144 kilobytes

input: standard

output: standard

output: standard

Inspired by Stephen Graham, the King of Berland started to study algorithms on strings. He was working days and nights, having a feeling that the full potential in this area is still to be unlocked. And he was right!

One day, all the sudden, he made a huge breakthrough by discovering the fact that strings can be magically transformed into integer numbers. It was so simple! You just have to map different letters to different digits and be careful enough not to introduce any leading zeroes.

Here is what he wrote in his textbook about the string 'lalala':

- it can be transformed to an 282828 by mapping 'l' to 2, and 'a' to 8
- it can also be transformed to 909090 by mapping 'l' to 9, and 'a' to 0
- a couple of examples of invalid transformations are 050505 (the resulting number has a leading zero), 333333 (different letters are mapped to the same digit), 123456 (no mapping to the original letters at all)

But then things started to become more interesting. Obviously, it was known from very beginning that a single string can potentially be mapped to a variety of different integer numbers. But the King couldn't even imagine that all numbers produced by the same string pattern might have common properties!

For example, every single number that can be produced from string 'lalala' is always divisible by 259, irrespective of the letter-to-digit mapping you choose. Fascinating!

So the King ended up with the following problem. For any given string, he wanted to come up with an algorithm to calculate the set of its divisors. A number is called a divisor of the given string if all positive integers, that could possibly be produced from the given string, are divisible by it.

As usual, the King desperately wants you to help him, so stop thinking and start acting!

Each of the next

sample input | sample output |

5 cat bbb ololo lala icpcicpc | Case 1: 1 Case 2: 1 3 37 111 Case 3: 1 Case 4: 1 101 Case 5: 1 73 137 10001 |

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Aug/09/2020 17:54:51 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|