LotteryCheating
SRM 466 · 2009-11-12 · by Chmel_Tolstiy
Problem Statement
Unfortunately, Bob only has enough money to buy one ticket, and he cannot see the identifier before buying a ticket. Therefore, he decides to cheat by buying a ticket and modifying its identifier to make it a winning ticket. In a single change operation, he can choose one digit, erase it, and print some other digit in the same position. No other types of modifications are allowed. He can perform any number of these change operations, but he wants to perform as few as possible to minimize the risk of getting caught.
You are given a
Constraints
- ID will contain between 1 and 10 characters, inclusive.
- Each character in ID will be between '0' and '9', inclusive.
"1" Returns: 0
1 is the only divisor of this identifier. Since there are an odd number of divisors, it is already a winning ticket, and no changes are necessary.
"1234" Returns: 2
One possible solution is to transform "1234" into "1024". As 1024 is 2^10, it has 11 divisors: 2^0, 2^1, ..., 2^10.
"9000000000" Returns: 1
Bob can change the '9' into a '0'. The resulting identifier "0000000000" contains only '0's, so it is a winning ticket.
"4294967296" Returns: 0
The initial identifier represents the integer 2^32, so it has 33 divisors.
"7654321" Returns: 3
Submissions are judged against all 266 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LotteryCheating with a public method int minimalChange(string ID) · 266 test cases · 2 s / 256 MB per case