結果
| 問題 |
No.1185 完全な3の倍数
|
| コンテスト | |
| ユーザー |
ManjushriMitra
|
| 提出日時 | 2024-12-08 18:29:40 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 1,224 bytes |
| コンパイル時間 | 2,796 ms |
| コンパイル使用メモリ | 252,256 KB |
| 実行使用メモリ | 15,616 KB |
| 最終ジャッジ日時 | 2024-12-08 18:29:46 |
| 合計ジャッジ時間 | 5,597 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<int(n); ++i)
#define repll(i,m,n) for(ll i=m; i<ll(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define fi first
#define se second
template<typename T> bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; }
template<typename T> bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; }
template<typename T> T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; }
template<typename T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin >> N;
set<ll> st;
for(ll i = 12LL; i <= min(100LL, N); i += 3LL){
string s = to_string(i);
if(((s[0] - '0') + (s[1] - '0')) % 3 == 0) st.insert(i);
}
auto rec = [&](auto rec, ll x) -> void {
if(x > N) return;
if(x >= 10LL) st.insert(x);
if(x) rec(rec, x*10LL + 0LL);
rec(rec, x*10LL + 3LL);
rec(rec, x*10LL + 6LL);
rec(rec, x*10LL + 9LL);
};
rec(rec, 0LL);
// for(ll s : st) cout << s << endl;
cout << st.size() << endl;
return 0;
}
ManjushriMitra