No.3157 Nabeatsu
問題文最終更新日: 2025-05-23 19:01:01
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
KCPC新歓杯 -Happy Birthday physics0523-
(順位表)
の他の問題:
Problem Statement
A positive integer satisfying at least one of the following conditions is called a Nabeatsu number:
- It is a multiple of $3$
- It contains the digit $3$ when written in base $10$
You are given a positive integer $N$. Print the largest positive integer not exceeding $N$ that is not a Nabeatsu number.
Constraints
- $N$ is a positive integer at most $10^{10^6}=10^{1000000}$
Input
The input is given from standard input in the following format.
$N$
Output
Print the largest positive integer not exceeding $N$ that is not a Nabeatsu number.
Sample
Sample 1
Input
430
Output
428
$430$ contains $3$, so it is a Nabeatsu number.
$429$ is a multiple of $3$, so it is a Nabeatsu number.
$428$ is not a multiple of $3$ and does not contain $3$, so it is not a Nabeatsu number.
Sample 2
Input
333
Output
299
Sample 3
Input
271828182845904523536
Output
271828182845904522998
$N$ can be very large.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
jastaway
butsurizuki