A The Miracle and the Sleeper

水题  只要知道数学公式就行了

找出2个数中最大的取模值

#include "bits/stdc++.h"
#define ll long long
using namespace std;
ll t;
int main()
{
    cin >> t;
    while (t--)
    {
        ll l,r;
        cin >> l >> r; 
        if((r/2+1)>l){         // r/2+1 >l 存在  那么最大值是r%(r/2+1) 否则是 r%l
            cout <<r%(r/2+1) << endl;
        }else{
            cout << r%l << endl;
        }
 
 
    }
 
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_53013914/article/details/120019858