Advertisement
theo830

code

Sep 8th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. long long t;
  5. cin>>t;
  6. while(t--){
  7. long long n,m;
  8. cin>>n>>m;
  9. long long st=m;
  10. if(n == 1 && m == 1){
  11. cout<<1<<endl;
  12. }
  13. else if(n == 2 && m == 1){
  14. cout<<1<<endl;
  15. }
  16. else if(m == n-1){
  17. cout<<2<<endl;
  18. }
  19. else if(m < n-1){
  20. cout<<-1<<endl;
  21. }
  22. else if(m > n+(((n-1)*n))/2){
  23. cout<<-1<<endl;
  24. }
  25. else{
  26. m-=n+1;
  27. if(m <= 0){
  28. cout<<2<<endl;
  29. }
  30. else{
  31. m-=n-1;
  32. if(m<=0){
  33. cout<<3<<endl;
  34. }
  35. else{
  36. m*=2;
  37. cout<<(m+n-1)/n+3<<endl;
  38. }
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement