結果

問題 No.2262 Fractions
ユーザー karinohitokarinohito
提出日時 2023-03-11 13:21:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 1,398 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 207,476 KB
実行使用メモリ 6,072 KB
最終ジャッジ日時 2024-05-05 07:18:24
合計ジャッジ時間 12,415 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
5,248 KB
testcase_01 AC 175 ms
5,376 KB
testcase_02 AC 149 ms
5,376 KB
testcase_03 AC 147 ms
5,376 KB
testcase_04 AC 156 ms
5,376 KB
testcase_05 AC 141 ms
5,376 KB
testcase_06 AC 154 ms
5,376 KB
testcase_07 AC 146 ms
5,376 KB
testcase_08 AC 135 ms
5,376 KB
testcase_09 AC 145 ms
5,376 KB
testcase_10 AC 145 ms
5,376 KB
testcase_11 AC 200 ms
5,376 KB
testcase_12 AC 200 ms
5,376 KB
testcase_13 AC 202 ms
5,376 KB
testcase_14 AC 202 ms
5,376 KB
testcase_15 AC 200 ms
5,376 KB
testcase_16 AC 96 ms
5,376 KB
testcase_17 AC 97 ms
5,376 KB
testcase_18 AC 96 ms
5,376 KB
testcase_19 AC 224 ms
5,376 KB
testcase_20 AC 213 ms
5,376 KB
testcase_21 AC 226 ms
5,376 KB
testcase_22 AC 209 ms
5,376 KB
testcase_23 AC 180 ms
5,376 KB
testcase_24 AC 237 ms
5,888 KB
testcase_25 AC 247 ms
5,888 KB
testcase_26 AC 239 ms
5,888 KB
testcase_27 AC 240 ms
5,888 KB
testcase_28 AC 238 ms
6,072 KB
testcase_29 AC 246 ms
5,916 KB
testcase_30 AC 245 ms
5,916 KB
testcase_31 AC 252 ms
5,888 KB
testcase_32 AC 246 ms
5,916 KB
testcase_33 AC 251 ms
6,016 KB
testcase_34 AC 247 ms
5,888 KB
testcase_35 AC 223 ms
5,916 KB
testcase_36 AC 222 ms
5,916 KB
testcase_37 AC 11 ms
5,888 KB
testcase_38 AC 11 ms
5,888 KB
testcase_39 AC 223 ms
5,376 KB
testcase_40 AC 227 ms
5,376 KB
testcase_41 AC 226 ms
5,376 KB
testcase_42 AC 225 ms
5,376 KB
testcase_43 AC 222 ms
5,376 KB
testcase_44 AC 247 ms
5,916 KB
testcase_45 AC 246 ms
5,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define rep(i,s,t,p) for(int i=s;i<t;i+=p)
vll PR;

void mobius(vll&A){
    ll N=A.size();
    for (auto p:PR) {
        if(p>N)break;
        for(int i=(N-1)/p;i>=1;i--) {
            A[p*i]-=A[i];
        }
    }
    return;
}

ll b=(1ll<<40);
ll num(ll p,ll N){//p/b以下分母がN以下の既約分数
    ll S=0;
    vll F(N+1,0);
    rep(i,1,N+1,1){
        F[i]+=(p*i)/b;//分母がiで mid/N以下の(既約とは限らない)分数の個数
    }
    mobius(F);
    rep(i,1,N+1,1)S+=F[i];
    return S;
}

int main() {
    ll NINF=3e5+1,T,N,K;
    vector<bool> P(NINF,1);
    rep(i,2,NINF,1)if(P[i]){
        PR.push_back(i);
        rep(j,2*i,NINF,i)P[j]=0;
    }
    cin>>T;
    while(cin>>N>>K){
        ll L=num(b,N)-1;
        bool INV=0;
        if(K==L+1){
            cout<<"1/1"<<endl;
            continue;
        }
        if(K>2*L+1){
            cout<<-1<<endl;
            continue;
        }
        if(K>L+1){
            INV=1;
            K=2*L-K+2;
        }
        ll l=0,r=b+1;
        while(r-l>1)(num((r+l)/2,N)<K?l:r)=(r+l)/2;
        vll F(N+1,0);
        pair<ll,ll> P;
        rep(i,1,N+1,1){
            ll a=(r*i)/b;
            if(gcd(a,i)==1)if(a*b>=l*i)P={a,i};
        }
        if(INV)swap(P.first,P.second);
        cout<<P.first<<"/"<<P.second<<endl;
    }
}
0