fork download
  1. #include <iostream>
  2. #include<vector>
  3. #include<climits>
  4. using namespace std;
  5.  
  6. int main() {
  7. int t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. int n,k;
  12. cin>>n>>k;
  13. vector<int>vec(n);
  14. for (int i = 0; i < n; ++i)
  15. {
  16. cin>>vec[i]; }
  17.  
  18. int ans=INT_MAX;
  19. for (int i = 0; i < n; ++i)
  20. { if(vec[i]%k==0)
  21. {
  22. ans=0;
  23. break;
  24. }
  25.  
  26. else
  27. {ans=min(ans,k-vec[i]%k);}
  28. }
  29.  
  30. cout<<ans<<endl;
  31.  
  32. }
  33.  
  34. }
  35.  
Success #stdin #stdout 0.01s 5292KB
stdin
15
2 5
7 3
3 3
7 4 1
5 2
9 7 7 3 9
5 5
5 4 1 2 3
7 4
9 5 1 5 9 5 1
3 4
6 3 6
3 4
6 1 5
3 4
1 5 9
4 4
1 4 1 1
3 4
3 5 3
4 5
8 9 9 3
2 5
1 6
2 5
10 10
4 5
1 6 1 1
2 5
7 7
stdout
2
2
1
0
3
1
2
3
0
1
1
4
0
4
3