Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.

book
Custom Subtraction

A young girl named Emily is learning how to subtract one from a number, but she has a unique way of doing it when the number has two or more digits.

Emily follows these steps:

  • If the last digit of the number is not zero, she simply subtracts one from the number.
  • If the last digit of the number is zero, she divides the number by 10 (effectively removing the last digit).

You are given an integer number n. Emily will perform this subtraction process k times. Your task is to determine the final result after all k subtractions. It is guaranteed that the result will always be a positive integer.

Example 1

Input:

n = 512, k = 4

Output:

50

Explanation:

512→511→510→51→50
main.cpp

main.cpp

C++

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt