-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpring.cpp
More file actions
54 lines (48 loc) · 1.05 KB
/
Spring.cpp
File metadata and controls
54 lines (48 loc) · 1.05 KB
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
51
52
53
54
/*
AUTHOR: Antarikshya Mitra
TIME:
PROBLEM NO:- Spring
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
long long lcm(long long a, long long b){
return (a / __gcd(a,b)) * b;
}
void solve(int a, int b, int c, int m)
{
vector<int> Storage(3,0);
// Alice Bob Carol
int NA = m/a;
int NB = m/b;
int NC = m/c;
int NABC = m/lcm(lcm(a,b),c);
int NAB = m/lcm(a,b);
int NBC = m/lcm(b,c);
int NAC = m/lcm(a,c);
// Filling A
Storage[0] = NABC*2 + (NAB - NABC)*3 + (NAC - NABC)*3 + (NA - NAC - NAB + NABC)*6;
Storage[1] = NABC*2 + (NAB - NABC)*3 + (NBC - NABC)*3 + (NB - NBC - NAB + NABC)*6;
Storage[2] = NABC*2 + (NAC - NABC)*3 + (NBC - NABC)*3 + (NC - NAC - NBC + NABC)*6;
for(int i=0;i<3;i++)
cout<<Storage[i]<<" ";
cout<<endl;
return;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--)
{
int a,b,c,m;
cin>>a>>b>>c>>m;
solve(a,b,c,m);
}
return 0;
}