結果
| 問題 | No.1185 完全な3の倍数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-02 20:39:42 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 707 bytes |
| 記録 | |
| コンパイル時間 | 1,622 ms |
| コンパイル使用メモリ | 216,696 KB |
| 実行使用メモリ | 7,964 KB |
| 最終ジャッジ日時 | 2026-06-27 21:05:12 |
| 合計ジャッジ時間 | 3,902 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}