結果
| 問題 | 
                            No.1185 完全な3の倍数
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-10-02 20:39:42 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 6 ms / 2,000 ms | 
| コード長 | 707 bytes | 
| コンパイル時間 | 2,080 ms | 
| コンパイル使用メモリ | 198,192 KB | 
| 最終ジャッジ日時 | 2025-02-07 20:38:58 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 39 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll N; cin >> N;
    // 2桁 => 3の倍数
    int ans = 0;
    for(int i = 10; i <= min(99LL, N); i++)
        if(i % 3 == 0) ans++;
    // 3桁以上 => 各桁の数字 in {0, 3, 6, 9}
    queue<ll> q;
    for(int d : {3, 6, 9}) q.push(d);
    while(!q.empty()) {
        ll x = q.front(); q.pop();
        for(int d : {0, 3, 6, 9}) {
            x = x * 10 + d;
            if(x <= N) {
                if(100 <= x) ans++;
                q.push(x);
            }
            x /= 10;
        }
    }
    cout << ans << endl;
}