問題一覧 > 通常問題

No.3157 Nabeatsu

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 102
作問者 : TKTYI / テスター : 👑 kencho tatesoto 👑 みうね jastaway fluorine kmmtkm butsurizuki
お気に入りにしたユーザー ProblemId : 12236 / 自分の提出
問題文最終更新日: 2025-05-23 19:01:01
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もしくは右上の雲マークをクリックしてアカウントを作成してください。