結果

問題 No.1185 完全な3の倍数
ユーザー trineutron
提出日時 2020-08-22 13:50:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 538 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-24 09:26:59
合計ジャッジ時間 2,208 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
n = n // 3 * 3
if n < 100:
    ans = 0
    for i in range(1, 10):
        for j in range(0, 10):
            if 10 * i + j <= n and (i + j) % 3 == 0:
                ans += 1
    print(ans)
else:
    s = list(map(int, str(n)))
    d = len(s)
    for i in range(d):
        if s[i] % 3:
            s[i] = s[i] // 3
            for j in range(i + 1, d):
                s[j] = 3
            break
        else:
            s[i] //= 3
    ans = 15
    for i in range(d):
        ans += s[i] * 4**(d - 1 - i)
    print(ans)
0