#37684: 神秘的公式解


samlin961112@gmail.com (林哲甫)

學校 : 新北市私立南山高級中學
編號 : 220506
來源 : [219.70.213.92]
最後登入時間 :
2024-05-06 16:41:02
g877. 遺失的鑽石 -- 板中資訊APCS班程式挑戰賽 | From: [219.70.213.92] | 發表日期 : 2023-09-29 00:07

#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;

  while (t--) {
    int n, k;
    cin >> n >> k;
    if (n % 2 == 0) {
      if(k%n==0){
        cout<<n<<'\n';
      }else{
      cout << k % n << '\n';
      }
    } else if (n == 1) {
      cout << 1 << '\n';
    } else {
      cout << (k - 1 + (k - 1) / (n / 2)) % n + 1 << '\n';
    }
  }
}

 
ZeroJudge Forum