らての精進日記

修行をします

aoj0297:The Last One is the Best

解法

k%p番目の人が勝つ。ただし、k%p==0のときは答えがk%pではなくpになる。

コード

#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin>>n;
 
    while(n--){
        int k,p;
        cin>>k>>p;
        cout<<(k%p?k%p:p)<<endl;
    }
 
    return 0;
}