結果

問題 No.2262 Fractions
ユーザー 👑 kmjpkmjp
提出日時 2023-04-08 00:04:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,718 ms / 2,000 ms
コード長 1,857 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 200,200 KB
実行使用メモリ 20,244 KB
最終ジャッジ日時 2024-04-10 18:21:40
合計ジャッジ時間 51,925 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,019 ms
19,896 KB
testcase_01 AC 203 ms
20,160 KB
testcase_02 AC 204 ms
20,104 KB
testcase_03 AC 210 ms
20,112 KB
testcase_04 AC 230 ms
19,992 KB
testcase_05 AC 228 ms
20,132 KB
testcase_06 AC 232 ms
20,028 KB
testcase_07 AC 224 ms
20,140 KB
testcase_08 AC 213 ms
20,024 KB
testcase_09 AC 232 ms
20,036 KB
testcase_10 AC 233 ms
20,244 KB
testcase_11 AC 878 ms
20,156 KB
testcase_12 AC 864 ms
20,048 KB
testcase_13 AC 869 ms
20,144 KB
testcase_14 AC 876 ms
19,940 KB
testcase_15 AC 857 ms
20,140 KB
testcase_16 AC 486 ms
20,004 KB
testcase_17 AC 482 ms
19,956 KB
testcase_18 AC 482 ms
20,140 KB
testcase_19 AC 1,444 ms
20,092 KB
testcase_20 AC 1,413 ms
20,120 KB
testcase_21 AC 1,444 ms
20,016 KB
testcase_22 AC 1,339 ms
20,124 KB
testcase_23 AC 1,182 ms
20,180 KB
testcase_24 AC 1,620 ms
20,044 KB
testcase_25 AC 1,608 ms
20,180 KB
testcase_26 AC 1,591 ms
20,136 KB
testcase_27 AC 1,636 ms
20,028 KB
testcase_28 AC 1,594 ms
20,016 KB
testcase_29 AC 1,589 ms
20,140 KB
testcase_30 AC 1,622 ms
19,904 KB
testcase_31 AC 1,630 ms
20,052 KB
testcase_32 AC 1,607 ms
20,148 KB
testcase_33 AC 1,559 ms
20,180 KB
testcase_34 AC 1,562 ms
20,212 KB
testcase_35 AC 1,661 ms
20,196 KB
testcase_36 AC 1,718 ms
20,096 KB
testcase_37 AC 91 ms
20,036 KB
testcase_38 AC 94 ms
20,136 KB
testcase_39 AC 1,473 ms
20,012 KB
testcase_40 AC 1,472 ms
20,132 KB
testcase_41 AC 1,477 ms
20,112 KB
testcase_42 AC 1,462 ms
20,072 KB
testcase_43 AC 1,506 ms
20,184 KB
testcase_44 AC 1,653 ms
20,144 KB
testcase_45 AC 1,706 ms
20,068 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<int> D[302020];

int hoge(ll p,int q) {
	int ret=0,i;
	int mask,N=D[q].size();
	p=min(p,(ll)q-1);
	FOR(mask,1<<N) {
		int m=1,s=1;
		FOR(i,N) if(mask&(1<<i)) m*=D[q][i], s=-s;
		ret+=s*(p/m);
	}
	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=2;i<=300000;i++) if(D[i].empty()) {
		for(j=i;j<=300000;j+=i) D[j].push_back(i);
	}
	
	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