-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBella_ciao.cpp
More file actions
41 lines (36 loc) · 802 Bytes
/
Bella_ciao.cpp
File metadata and controls
41 lines (36 loc) · 802 Bytes
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
// Author : Deepdarshan
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define For(i, a, n, k) for (ll i = a; i < n; i += k)
void solve();
int main()
{
ll t;
cin >> t;
while (t--)
solve();
return 0;
}
void solve()
{
ll D, d, P, Q;
cin >> D >> d >> P >> Q;
ll amount = 0;
int i = 1;
if (D % d == 0)
{
amount = d * ((D / d) * P + Q * ((D / d - 1) * (D / d) / 2));
cout << amount << endl;
}
else
{
ll temp;
temp = D % d;
amount = d * ((D / d) * P + Q * ((D / d - 1) * (D / d) / 2));
// cout << "P " << P << endl;
amount += (P + (D / d) * Q) * temp;
cout << amount << endl;
}
// cout << amount << endl;
}