結果
問題 |
No.1006 Share an Integer
|
ユーザー |
|
提出日時 | 2025-05-04 03:33:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 452 ms / 2,000 ms |
コード長 | 1,719 bytes |
コンパイル時間 | 2,257 ms |
コンパイル使用メモリ | 207,908 KB |
実行使用メモリ | 57,904 KB |
最終ジャッジ日時 | 2025-05-04 03:33:40 |
合計ジャッジ時間 | 8,709 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template <typename T> bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template <typename T> bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct IOST { IOST() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); } } IOST; namespace cho { using std::vector; vector<int> prime_table(int n) { vector<int> p(n + 1, -1); for (int i = 2; i * i <= n; i++) { if (p[i] != -1) continue; for (int j = i * i; j <= n; j += i) { p[j] = i; } p[i] = i; } return p; } std::set<int> prime_set(int n) { std::set<int> res; auto p = prime_table(n); for (int i = 2; i <= n; i++) { if (p[i] == i) res.insert(i); } return res; } vector<int> prime_list(int n) { vector<int> res; auto p = prime_table(n); for (int i = 2; i <= n; i++) { if (p[i] == i) res.push_back(i); } return res; } std::map<int, int> table_factor(int n) { const static vector<int> table = prime_table(1e7); assert(n <= 1e7); std::map<int, int> res; while (n > 1) { res[table[n]]++; n /= table[n]; } return res; } } // namespace cho void solve() { auto d_N = [](int n) { if (n <= 0) return 0LL; auto mp = cho::table_factor(n); ll res = 1; for (auto [x, ct] : mp) res *= (ct + 1); return res; }; int n; cin >> n; vector<ll> f(n + 1); rep(i, 1, n) f[i] = i - d_N(i); ll mn = 1e18; rep(i, 1, n) chmin(mn, abs(f[i] - f[n - i])); rep(i, 1, n) { if (mn == abs(f[i] - f[n - i])) cout << i << " " << n - i << "\n"; } } int main() { int t = 1; // cin >> t; rep(i, 0, t) solve(); }