๐Ÿ“ฆ ved015 / Codeforces-solution

๐Ÿ“„ catslot1200.cpp ยท 25 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <iostream>
using namespace std;
int solve(int n,int k){
    if(n%2 == 0){
        int val = k%n;
        if(val == 0) val = n;
        return val;
    }
    else{
        k--;
        int rem = n/2;
        return 1 + (k + (k/rem))%n;
    }
}
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n,k;
        cin >> n >> k;
        cout << solve(n,k) << endl;
    }
    return 0;
}