Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int mod(string num,int a);
  4.  
  5. int main() {
  6.  
  7. int t;
  8.  
  9. cin >> t;
  10.  
  11. while(t--)
  12. {
  13. long long int n;
  14. cin >> n;
  15. string k;
  16. cin >> k;
  17. int t;
  18. t = mod(k,n);
  19.  
  20. if(t==0)
  21. {
  22. cout << 0 << endl;
  23. }
  24.  
  25. else if(t < n/2.0 )
  26. {
  27. cout << 2*t << endl;
  28. }
  29.  
  30. else if(t == n/2.0)
  31. {
  32. cout << 2*t - 1<<endl;
  33. }
  34. else
  35. {
  36. cout << 2*(n-t)<<endl;
  37. }
  38.  
  39.  
  40.  
  41. }
  42.  
  43. return 0;
  44. }
  45.  
  46. int mod(string num,int a)
  47. {
  48. int res = 0;
  49. int i;
  50.  
  51. for(i = 0;i<num.length();i++)
  52. {
  53. res = (res*10 + num[i] - '0')%a;
  54.  
  55. }
  56.  
  57. return res;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement