結果
問題 |
No.2262 Fractions
|
ユーザー |
![]() |
提出日時 | 2023-04-08 00:04:33 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,939 ms / 2,000 ms |
コード長 | 1,857 bytes |
コンパイル時間 | 7,043 ms |
コンパイル使用メモリ | 259,772 KB |
最終ジャッジ日時 | 2025-02-12 03:22:50 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
#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; }