0% found this document useful (0 votes)
2 views

Problem - B - Codeforces

The document presents a problem from Codeforces Round 1016 (Div. 3) regarding the cost of a positive integer, defined as the integer divided by the sum of its digits. Participants must determine the minimum number of digits to remove from a given integer to achieve the lowest possible cost. The problem includes input and output specifications, as well as examples for clarification.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Problem - B - Codeforces

The document presents a problem from Codeforces Round 1016 (Div. 3) regarding the cost of a positive integer, defined as the integer divided by the sum of its digits. Participants must determine the minimum number of digits to remove from a given integer to achieve the lowest possible cost. The problem includes input and output specifications, as well as examples for clarification.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

22:21 8/4/25 Problem - B - Codeforces

|
QuanVanHoang | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS STANDINGS CUSTOM INVOCATION

Codeforces Round 1016 (Div. 3)


B. Expensive Number Contest is running
time limit per test: 1 second
01:28:10
memory limit per test: 256 megabytes
Contestant
The cost of a positive integer n is defined as the result of dividing the number n by the sum of its
digits.

For example, the cost of the number 104 is


104
= 20.8 , and the cost of the number 111 is
→ Submit?
1+0+4
111
= 37 .
1+1+1

You are given a positive integer n that does not contain leading zeros. You can remove any Language: Python 3.13.2
Almost always, if you send a solution
number of digits from the number n (including none) so that the remaining number contains at on PyPy, it works much faster
least one digit and is strictly greater than zero. The remaining digits cannot be rearranged. As Choose
Chọn tệp Không có …được chọn
a result, you may end up with a number that has leading zeros. file:

For example, you are given the number 103554. If you decide to remove the digits 1, 4, and one Submit

digit 5, you will end up with the number 035, whose cost is
035
= 4.375 .
0+3+5

What is the minimum number of digits you need to remove from the number so that its cost
becomes the minimum possible?

Input
The first line contains an integer t (1 ≤ t ≤ 1000 ) — the number of test cases.

100
The only line of each test case contains a positive integer n (1 ≤ n < 10 ) without leading
zeros.

Output
For each test case, output one integer on a new line — the number of digits that need to be
removed from the number so that its cost becomes minimal.

Example
input Copy

4
666
13700
102030
7

output Copy

2
4
3
0

Codeforces (c) Copyright 2010-2025 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Apr/08/2025 22:15:20UTC+7 (g1).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions

Supported by

https://codeforces.com/contest/2093/problem/B 1/2

You might also like