結果

問題 No.2262 Fractions
ユーザー umezoumezo
提出日時 2023-04-07 22:53:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,368 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 198,500 KB
実行使用メモリ 38,200 KB
最終ジャッジ日時 2024-04-10 17:44:39
合計ジャッジ時間 8,800 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

ll eulerPhi(ll n) {
    if (n == 0){
        return (0);
    }
    ll ans = n;
    for(ll x = 2; x * x <= n; ++x){
        if (n % x == 0) {
            ans -= ans / x;
            while (n % x == 0){
                n /= x;
            }
        }
    }
    if (n > 1){
        ans -= ans / n;
    }
    return (ans);
}

int MAX=300300;

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  vector<ll> euler(MAX);  
  for(int i = 1; i <= MAX; i++) euler[i] = eulerPhi(i);
  for(int i = 1; i <= MAX; i++) euler[i] += euler[i - 1];
  
  int t;
  cin>>t;
  while(t--){
    ll n,k;
    cin>>n>>k;
    ll a=euler[n];
    if(k>=2*a){
      cout<<-1<<'\n';
      continue;
    }
    if(k==a){
      cout<<"1/1\n";
      continue;
    }
    int c=0;
    if(k>a){
      k=2*a-k;
      c=1;
    }
    
    ll idx=0;
    auto make=[&](auto make,ll a1,ll a2,ll b1,ll b2)->void{
      ll c1 = a1 + b1, c2 = a2 + b2;
      if (idx > k) return;
      if (c2 > n) return;
      make(make,a1, a2, c1, c2);
      idx++;
	  if(idx == k){
		if(c==0) cout<<c1<<'/'<<c2<<"\n";
        else cout<<c2<<'/'<<c1<<"\n";
		return;
      }
	  make(make,c1, c2, b1, b2);
    };
    
    make(make,0,1,1,1);
  }
    
  return 0;
}
0