-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHFMOT18.cpp
51 lines (46 loc) · 893 Bytes
/
CHFMOT18.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define lli long long int
#define vi vector<int>
#define vll vector<lli>
#define pb push_back
#define all(v) v.begin(),v.end()
void solve(){
int s, n;
cin >> s >> n;
if(n%2!=0){
n--;
}
int num_coins = 0;
while(s>1){
if(s < n){
if(s %2 == 0){
n = s;
}else{
n = s-1;
}
}else{
num_coins += s / n;
s -= (s/n)*n;
}
}
if(s == 1){
num_coins++;
}
cout << num_coins << endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test_cases;
//test_cases = 1;
cin >> test_cases;
while(test_cases--){
solve();
}
return 0;
}