結果

問題 No.2262 Fractions
ユーザー 👑 kmjpkmjp
提出日時 2023-04-08 00:09:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,129 ms / 2,000 ms
コード長 1,908 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 206,972 KB
実行使用メモリ 37,120 KB
最終ジャッジ日時 2024-05-05 07:28:18
合計ジャッジ時間 36,531 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 755 ms
36,992 KB
testcase_01 AC 265 ms
36,992 KB
testcase_02 AC 257 ms
36,864 KB
testcase_03 AC 260 ms
36,992 KB
testcase_04 AC 272 ms
36,992 KB
testcase_05 AC 264 ms
36,864 KB
testcase_06 AC 263 ms
36,992 KB
testcase_07 AC 281 ms
36,992 KB
testcase_08 AC 276 ms
36,992 KB
testcase_09 AC 273 ms
36,992 KB
testcase_10 AC 271 ms
36,864 KB
testcase_11 AC 599 ms
36,992 KB
testcase_12 AC 578 ms
36,992 KB
testcase_13 AC 594 ms
36,992 KB
testcase_14 AC 585 ms
36,864 KB
testcase_15 AC 583 ms
36,992 KB
testcase_16 AC 306 ms
37,120 KB
testcase_17 AC 311 ms
36,992 KB
testcase_18 AC 301 ms
36,992 KB
testcase_19 AC 946 ms
36,992 KB
testcase_20 AC 874 ms
36,864 KB
testcase_21 AC 974 ms
36,992 KB
testcase_22 AC 882 ms
36,992 KB
testcase_23 AC 785 ms
36,992 KB
testcase_24 AC 1,083 ms
36,992 KB
testcase_25 AC 1,040 ms
36,864 KB
testcase_26 AC 1,078 ms
36,992 KB
testcase_27 AC 1,129 ms
36,992 KB
testcase_28 AC 1,063 ms
37,120 KB
testcase_29 AC 1,065 ms
36,992 KB
testcase_30 AC 1,075 ms
36,992 KB
testcase_31 AC 1,093 ms
36,992 KB
testcase_32 AC 1,085 ms
36,992 KB
testcase_33 AC 1,060 ms
36,992 KB
testcase_34 AC 1,061 ms
36,992 KB
testcase_35 AC 702 ms
36,992 KB
testcase_36 AC 753 ms
36,992 KB
testcase_37 AC 182 ms
36,992 KB
testcase_38 AC 195 ms
36,992 KB
testcase_39 AC 948 ms
36,992 KB
testcase_40 AC 1,004 ms
36,992 KB
testcase_41 AC 990 ms
36,992 KB
testcase_42 AC 976 ms
36,864 KB
testcase_43 AC 935 ms
36,992 KB
testcase_44 AC 1,122 ms
36,992 KB
testcase_45 AC 1,103 ms
36,992 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&&tot<K;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