K-equivalence
Time limit1sMemory limit128 MB
Given a finite set K of positive integers described as disjoint intervals, determine which decimal digits 1-9 can always be swapped in any number of K without leaving K, and output the resulting equivalence classes.
- Level
Hard8 of 10
- Topics
- Math, Simulation, Implementation
- Solved
- No attempts yet
Problem
Consider a set of positive integers.
Let and be two non-zero decimal digits. We call them -equivalent when the following holds:
For every , replacing a single digit by , or a single digit by , in the decimal representation of always yields a number that is again an element of .
For example, if is the set of integers divisible by , then the digits , , and are -equivalent: replacing a by a in the decimal representation of a number never changes its divisibility by .
-equivalence is an equivalence relation on the digits (it is reflexive, symmetric, and transitive).
You are given a finite set expressed as a union of pairwise-disjoint finite intervals of positive integers. Find the equivalence classes of the digits through .
Input
The first line contains , the number of intervals whose union forms ().
Each of the next lines contains two positive integers and that describe the interval (all integers with ), where . Moreover, for every with , (so the intervals are pairwise disjoint and given in increasing order).
Output
Represent each equivalence class as the concatenation of its digits in ascending order.
Print all equivalence classes of the digits through , one per line, sorted lexicographically.