Odpowiedź:
#include <iostream>
#define ull unsigned long long
using namespace std;
ull NWD (ull a, ull b) {
ull tmp;
while (b != 0) {
tmp = b;
b = a % b;
a = tmp;
}
return a;
int main() {
ull a, b, c, d, nww, nwd, nwd2;
char znak;
cin >> a >> znak >> b;
cin >> c >> znak >> d;
nwd = NWD(b, d);
nww = (b / nwd) * d;
a = (d / nwd) * a;
c = (b / nwd) * c;
nwd2 = NWD(a + c, nww);
cout << (a + c) / nwd2 << '/' << nww / nwd2 << endl;
return 0;
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
Odpowiedź:
#include <iostream>
#define ull unsigned long long
using namespace std;
ull NWD (ull a, ull b) {
ull tmp;
while (b != 0) {
tmp = b;
b = a % b;
a = tmp;
}
return a;
}
int main() {
ull a, b, c, d, nww, nwd, nwd2;
char znak;
cin >> a >> znak >> b;
cin >> c >> znak >> d;
nwd = NWD(b, d);
nww = (b / nwd) * d;
a = (d / nwd) * a;
c = (b / nwd) * c;
nwd2 = NWD(a + c, nww);
cout << (a + c) / nwd2 << '/' << nww / nwd2 << endl;
return 0;
}