MostFrequentLastDigit
TCO19 SRM 747 · 2019-01-09 · by misof
TCO19 SRM 747 · 2019-01-09 · by misof · Simple Math
Problem Statement
Problem Statement
You are given the
- The number of elements is n.
- Each element is between 0 and 10^9, inclusive.
- All elements are distinct.
- No element is divisible by 10.
- If we take all n*(n-1)/2 possible sums of two elements and look at the last digit of each of them, the digit d will be the unique most frequent one.
Constraints
- n will be between 2 and 200, inclusive.
- d will be between 0 and 9, inclusive.
Examples
0)
4
7
Returns: {1, 6, 13, 4 }
The pairwise sums are 7, 14, 5, 19, 10, and 17. The last digit 7 appears in two of them, and each other digit appears at most once as a last digit of one of these sums.
1)
2
8
Returns: {44, 444 }
Note that {4, 4} is not a valid return value because all numbers must be distinct.}
2)
7
2
Returns: {109, 22, 74, 23, 29, 9, 1003 }
3)
2
0
Returns: {6, 14 }
4)
2
1
Returns: {6, 15 }
Submissions are judged against all 149 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class MostFrequentLastDigit with a public method vector<int> generate(int n, int d) · 149 test cases · 2 s / 256 MB per case