Odpowiedź:
#include <bits/stdc++.h>
using namespace std;
int nwd(int a, int b)
{
int c;
do
c = a % b;
a = b;
b = c;
}
while(c != 0);
return a;
int main()
int L1,M1,L2,M2,L3,M3,tmp,LW,MW;
cin>>L1>>M1>>L2>>M2>>L3>>M3;
tmp = nwd(M1,M2);
MW = M1/tmp * M2;
LW = MW/M1*L1 + MW/M2*L2;
tmp = nwd(M3,MW);
MW = MW/tmp * M3;
LW += MW/M3*L3;
tmp = nwd(LW,MW);
cout<<LW/tmp<<"/"<<MW/tmp;
return 0;
Wyjaśnienie:
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
Odpowiedź:
#include <bits/stdc++.h>
using namespace std;
int nwd(int a, int b)
{
int c;
do
{
c = a % b;
a = b;
b = c;
}
while(c != 0);
return a;
}
int main()
{
int L1,M1,L2,M2,L3,M3,tmp,LW,MW;
cin>>L1>>M1>>L2>>M2>>L3>>M3;
tmp = nwd(M1,M2);
MW = M1/tmp * M2;
LW = MW/M1*L1 + MW/M2*L2;
tmp = nwd(M3,MW);
MW = MW/tmp * M3;
LW += MW/M3*L3;
tmp = nwd(LW,MW);
cout<<LW/tmp<<"/"<<MW/tmp;
return 0;
}
Wyjaśnienie: