結果

問題 No.2262 Fractions
ユーザー 👑 kmjpkmjp
提出日時 2023-04-08 00:08:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,144 ms / 2,000 ms
コード長 1,901 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 208,608 KB
実行使用メモリ 37,120 KB
最終ジャッジ日時 2024-05-06 14:53:13
合計ジャッジ時間 38,069 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 738 ms
36,948 KB
testcase_01 AC 276 ms
36,992 KB
testcase_02 AC 261 ms
36,852 KB
testcase_03 AC 272 ms
36,780 KB
testcase_04 AC 270 ms
36,944 KB
testcase_05 AC 264 ms
36,872 KB
testcase_06 AC 270 ms
36,892 KB
testcase_07 AC 271 ms
36,864 KB
testcase_08 AC 251 ms
36,992 KB
testcase_09 AC 282 ms
36,972 KB
testcase_10 AC 269 ms
36,772 KB
testcase_11 AC 580 ms
36,992 KB
testcase_12 AC 584 ms
36,984 KB
testcase_13 AC 582 ms
36,924 KB
testcase_14 AC 608 ms
36,992 KB
testcase_15 AC 585 ms
36,864 KB
testcase_16 AC 411 ms
36,764 KB
testcase_17 AC 390 ms
36,796 KB
testcase_18 AC 413 ms
36,940 KB
testcase_19 AC 932 ms
36,984 KB
testcase_20 AC 913 ms
36,948 KB
testcase_21 AC 1,021 ms
36,988 KB
testcase_22 AC 905 ms
37,060 KB
testcase_23 AC 731 ms
36,940 KB
testcase_24 AC 1,067 ms
37,120 KB
testcase_25 AC 1,050 ms
36,968 KB
testcase_26 AC 1,081 ms
36,928 KB
testcase_27 AC 1,100 ms
36,992 KB
testcase_28 AC 1,030 ms
36,992 KB
testcase_29 AC 1,088 ms
36,896 KB
testcase_30 AC 1,132 ms
36,908 KB
testcase_31 AC 1,144 ms
37,020 KB
testcase_32 AC 1,117 ms
36,924 KB
testcase_33 AC 1,114 ms
36,964 KB
testcase_34 AC 1,107 ms
36,992 KB
testcase_35 AC 1,124 ms
36,876 KB
testcase_36 AC 1,087 ms
37,120 KB
testcase_37 AC 190 ms
36,864 KB
testcase_38 AC 195 ms
36,992 KB
testcase_39 AC 961 ms
36,976 KB
testcase_40 AC 943 ms
36,992 KB
testcase_41 AC 980 ms
36,952 KB
testcase_42 AC 943 ms
36,956 KB
testcase_43 AC 951 ms
36,960 KB
testcase_44 AC 1,098 ms
36,924 KB
testcase_45 AC 1,088 ms
36,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T;
ll N,K;

vector<pair<int,int>> D[302020];

int hoge(ll p,int q) {
	int ret=0,i;
	int tp=min(p,(ll)q-1);
	FORR2(a,s,D[q]) ret+=s*(tp/a);
	return ret;
}

pair<ll,ll> hoge2(ll N,ll K) {
	ll L=0,R=1LL*N*N;
	int i;
	while(L+1<R) {
		ll M=(L+R)/2;
		ll tot=0;
		for(i=1;i<=N;i++) tot+=hoge(M*i/N/N,i);
		if(tot>=K) {
			R=M;
		}
		else {
			L=M;
		}
	}
	
	for(i=1;i<=N;i++) {
		ll a=hoge(R*i/N/N,i);
		ll b=hoge(L*i/N/N,i);
		if(a!=b) return {R*i/N/N,i};
	}
	return {0,0};
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	for(i=1;i<=300000;i++) D[i].push_back({1,1});
	
	for(i=2;i<=300000;i++) if(D[i].size()==1) {
		for(j=i;j<=300000;j+=i) {
			x=D[j].size();
			FOR(y,x) D[j].push_back({D[j][y].first*i,-D[j][y].second});
		}
	}
	
	cin>>T;
	while(T--) {
		cin>>N>>K;
		ll num=0;
		for(i=1;i<=N;i++) num+=hoge(i,i);
		if(K<=num) {
			pair<ll,ll> p=hoge2(N,K);
			cout<<p.first<<"/"<<p.second<<endl;
		}
		else if(K==num+1) {
			cout<<"1/1"<<endl;
		}
		else if(K<=2*num+1) {
			pair<ll,ll> p=hoge2(N,2*num+2-K);
			cout<<p.second<<"/"<<p.first<<endl;
		}
		else {
			cout<<-1<<endl;
		}
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0