Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int mod(string num,int a);
- int main() {
- int t;
- cin >> t;
- while(t--)
- {
- long long int n;
- cin >> n;
- string k;
- cin >> k;
- int t;
- t = mod(k,n);
- if(t==0)
- {
- cout << 0 << endl;
- }
- else if(t < n/2.0 )
- {
- cout << 2*t << endl;
- }
- else if(t == n/2.0)
- {
- cout << 2*t - 1<<endl;
- }
- else
- {
- cout << 2*(n-t)<<endl;
- }
- }
- return 0;
- }
- int mod(string num,int a)
- {
- int res = 0;
- int i;
- for(i = 0;i<num.length();i++)
- {
- res = (res*10 + num[i] - '0')%a;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement