結果

問題 No.3383 1122-like Number (C++)
コンテスト
ユーザー a01sa01to
提出日時 2025-11-27 00:58:59
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,034 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,282 ms
コンパイル使用メモリ 198,992 KB
実行使用メモリ 7,848 KB
スコア 0
最終ジャッジ日時 2025-11-27 00:59:55
合計ジャッジ時間 3,877 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1e18;

inline ll satulating_pow(ll a, int n) {
  ll cur = 1;
  rep(_, n) {
    if (cur > INF / a) return INF;
    cur *= a;
  }
  return cur;
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  vector<int> primes;
  {
    constexpr int m = 3.5e6;
    vector<bool> isPrime(m, true);
    for (int i = 2; i < m; ++i) {
      if (isPrime[i]) {
        primes.push_back(i);
        for (ll j = (ll) i * i; j < m; j += i) isPrime[j] = false;
      }
    }
  }
  int n;
  cin >> n;
  int ans = 0;
  function<void(int, int, ll)> dfs = [&](int idx, int cnt, ll cur) {
    if (cnt == 4) {
      assert(cur <= n);
      ans++;
      return;
    }
    for (int i = idx + 1; i < primes.size(); ++i) {
      if (satulating_pow(primes[i], 4 - cnt) > n / cur) break;
      dfs(i, cnt + 1, cur * primes[i]);
    }
  };
  dfs(-1, 0, 1);
  cout << ans << '\n';
  return 0;
}
0