結果

問題 No.1185 完全な3の倍数
ユーザー hiragn
提出日時 2020-08-26 02:46:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 2,726 ms
コンパイル使用メモリ 190,132 KB
最終ジャッジ日時 2025-01-13 14:55:15
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using lint = long long;

lint n;
int ans = 0;

void dfs(lint cur) {
    if (cur > n) return;
    if (cur > 100) ans++;

    dfs(cur * 10);
    dfs(cur * 10 + 3);
    dfs(cur * 10 + 6);
    dfs(cur * 10 + 9);
}

int main() {
    cin >> n;

    // 2桁の場合
    for (lint i = 12; i < 100 and i <= n; i += 3) {
        ans++;
    }

    // 3桁以上の場合
    dfs(3);
    dfs(6);
    dfs(9);

    cout << ans << endl;
    return 0;
}
0