fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. ll coins(int x){
  6. if(x==0) return 3;
  7. return (ll)pow(3,x+1) + (ll)x * (ll)pow(3,x-1);
  8. }
  9.  
  10. int main() {
  11. // your code goes here
  12. int t=1;
  13. cin>>t;
  14. while(t--){
  15. ll n,k;
  16. cin>>n>>k;
  17. if(k >=n ){
  18. cout<<n*3<<"\n";
  19. continue;
  20. }
  21. if(n > n*k){
  22. cout<<-1<<'\n';
  23. continue;
  24. }
  25. ll ans = k*3ll;
  26.  
  27. ll two = (n-k)/2;
  28. ans += two*7;
  29. n = n - (k + two*2);
  30. if(n){
  31. if(two == (k-1)){
  32. cout<<-1<<'\n';
  33. continue;
  34. }
  35. ans += 4;
  36. }
  37. cout<<ans<<"\n";
  38.  
  39.  
  40.  
  41.  
  42. }
  43. return 0;
  44. }
Success #stdin #stdout 0s 5308KB
stdin
8
1 1
3 3
8 3
2 4
10 10
20 14
3 2
9 1
stdout
3
9
-1
6
30
63
10
31