結果
問題 | No.2262 Fractions |
ユーザー | miscalc |
提出日時 | 2023-04-07 22:56:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,707 bytes |
コンパイル時間 | 4,801 ms |
コンパイル使用メモリ | 277,964 KB |
実行使用メモリ | 58,484 KB |
最終ジャッジ日時 | 2024-10-02 20:16:31 |
合計ジャッジ時間 | 61,916 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,196 ms
58,368 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 738 ms
58,452 KB |
testcase_17 | AC | 737 ms
58,368 KB |
testcase_18 | AC | 735 ms
58,340 KB |
testcase_19 | AC | 1,645 ms
58,304 KB |
testcase_20 | AC | 1,548 ms
58,252 KB |
testcase_21 | AC | 1,649 ms
58,284 KB |
testcase_22 | AC | 1,543 ms
58,348 KB |
testcase_23 | AC | 1,399 ms
58,376 KB |
testcase_24 | WA | - |
testcase_25 | AC | 1,770 ms
58,316 KB |
testcase_26 | AC | 1,735 ms
58,260 KB |
testcase_27 | AC | 1,753 ms
58,348 KB |
testcase_28 | AC | 1,720 ms
58,288 KB |
testcase_29 | AC | 1,898 ms
58,368 KB |
testcase_30 | AC | 1,664 ms
58,292 KB |
testcase_31 | AC | 1,770 ms
58,188 KB |
testcase_32 | AC | 1,764 ms
58,364 KB |
testcase_33 | AC | 1,766 ms
58,412 KB |
testcase_34 | AC | 1,704 ms
58,368 KB |
testcase_35 | AC | 153 ms
58,408 KB |
testcase_36 | AC | 1,773 ms
58,308 KB |
testcase_37 | AC | 188 ms
58,308 KB |
testcase_38 | AC | 186 ms
58,252 KB |
testcase_39 | WA | - |
testcase_40 | AC | 1,589 ms
58,416 KB |
testcase_41 | AC | 1,628 ms
58,260 KB |
testcase_42 | AC | 1,624 ms
58,424 KB |
testcase_43 | WA | - |
testcase_44 | AC | 1,675 ms
58,324 KB |
testcase_45 | AC | 1,775 ms
58,372 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = double; using pll = pair<ll, ll>; using tlll = tuple<ll, ll, ll>; constexpr ll INF = 1LL << 60; template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll safemod(ll A, ll M) {ll res = A % M; if (res < 0) res += M; return res;} ll divfloor(ll A, ll B) {if (B < 0) A = -A, B = -B; return (A - safemod(A, B)) / B;} ll divceil(ll A, ll B) {if (B < 0) A = -A, B = -B; return divfloor(A + B - 1, B);} ll pow_ll(ll A, ll B) {if (A == 0 || A == 1) {return A;} if (A == -1) {return B & 1 ? -1 : 1;} ll res = 1; for (int i = 0; i < B; i++) {res *= A;} return res;} ll mul_limited(ll A, ll B, ll M = INF) { return A > M / B ? M : A * B; } ll pow_limited(ll A, ll B, ll M = INF) { if (A == 0 || A == 1) {return A;} ll res = 1; for (int i = 0; i < B; i++) {if (res > M / A) return M; res *= A;} return res;} ll logfloor(ll A, ll B) {assert(A >= 2); ll res = 0; for (ll tmp = 1; tmp <= B / A; tmp *= A) {res++;} return res;} ll logceil(ll A, ll B) {assert(A >= 2); ll res = 0; for (ll tmp = 1; tmp < B; tmp *= A) {res++;} return res;} ll arisum_ll(ll a, ll d, ll n) { return n * a + (n & 1 ? ((n - 1) >> 1) * n : (n >> 1) * (n - 1)) * d; } ll arisum2_ll(ll a, ll l, ll n) { return n & 1 ? ((a + l) >> 1) * n : (n >> 1) * (a + l); } ll arisum3_ll(ll a, ll l, ll d) { assert((l - a) % d == 0); return arisum2_ll(a, l, (l - a) / d + 1); } template<class T> void unique(vector<T> &V) {V.erase(unique(V.begin(), V.end()), V.end());} template<class T> void sortunique(vector<T> &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) template<class T> void printvec(const vector<T> &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " ");cout << '\n';} template<class T> void printvect(const vector<T> &V) {for (auto v : V) cout << v << '\n';} template<class T> void printvec2(const vector<vector<T>> &V) {for (auto &v : V) printvec(v);} //* #include <atcoder/all> using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; //using mint = modint; //*/ // https://qiita.com/drken/items/3beb679e54266f20ab63 class eratosthenes { public: int N; vector<bool> isprime; vector<int> primecount; vector<int> primes; vector<int> minfactor; vector<int> mobius; eratosthenes(int n) { N = n; isprime.assign(n + 1, true); primecount.assign(n + 1, 0); minfactor.assign(n + 1, -1); mobius.assign(n + 1, 1); isprime[0] = false, isprime[1] = false; minfactor[1] = 1; for (int p = 2; p <= n; p++) { primecount[p] = primecount[p - 1]; if (!isprime[p]) continue; primecount[p]++; primes.emplace_back(p); minfactor[p] = p; mobius[p] = -1; for (int k = 2, q = 2 * p; q <= n; k++, q += p) { isprime[q] = false; if (minfactor[q] == -1) minfactor[q] = p; if (k % p == 0) mobius[q] = 0; else mobius[q] = -mobius[q]; } } } vector<pll> factorize(ll n) { vector<pll> ret; while (n > 1) { int p = minfactor[n]; int e = 0; while (minfactor[n] == p) { n /= p; e++; } ret.emplace_back(make_pair(p, e)); } return ret; } ll L; vector<vector<ll>> primefactors2; void rangesieve(ll l, ll r) { L = l; ll R = r; primefactors2.resize(R - L + 1); for (ll p = 2; p * p <= R; p++) { if (!isprime[p]) continue; for (ll v = divceil(L, p) * p; v <= R; v += p) { primefactors2[v - L].emplace_back(p); } } } vector<pll> factorize2(ll v) { vector<pll> ret; ll vv = v; const auto &pfs = primefactors2[v - L]; for (auto p : pfs) { ll e = 0; while (vv % p == 0) { vv /= p; e++; } ret.emplace_back(make_pair(p, e)); } if (vv > 1) ret.emplace_back(make_pair(vv, 1)); return ret; } }; const ll M = 300010; eratosthenes er(M); vector<vector<pll>> muls(M); void init() { for (ll i = 0; i < M; i++) { auto pes = er.factorize(i); ll k = pes.size(); for (ll b = 0; b < (1LL << k); b++) { ll mul = 1; for (ll j = 0; j < k; j++) { if (b & (1LL << j)) mul *= pes.at(j).first; } ll parity = __builtin_popcount(b) % 2 == 0 ? 1 : -1; muls.at(i).push_back({mul, parity}); } } } ll f(ll n, ll x) { ll ans = 0; for (auto [mul, parity] : muls.at(x)) { if (mul > n) break; if (parity == 1) ans += n / mul; else ans -= n / mul; } return ans; } string solve(ll N, ll K) { if (K == 1) return "1/" + to_string(N); auto isok = [&](ld x) -> bool { ll cnt = 0; for (ll q = 1; q <= N; q++) { ll n = q * x; cnt += f(min(N, n), q); } return cnt >= K; }; if (!isok(N)) return "-1"; ld ng = 1 / (ld)N, ok = N; for (int i = 0; i < 50; i++) { ld mid = sqrt(ok * ng); if (isok(mid)) ok = mid; else ng = mid; } string ans = ""; ld mn = INF; for (ll q = 1; q <= N; q++) { ll p = round(q * ok); if (!(1 <= p && p <= N)) continue; ld tmp = abs(ok - (ld)p / (ld)q); if (chmin(mn, tmp)) ans = to_string(p) + "/" + to_string(q); } return ans; } int main() { init(); ll T; cin >> T; while (T--) { ll N, K; cin >> N >> K; cout << solve(N, K) << endl; } }