import java.util.*;
import java.lang.*;
import java.io.*;
class Quaternion {
private double a;
private double b;
private double c;
private double d;
public Quaternion() {
a = 0;
b = 0;
c = 0;
d = 0;
}
public Quaternion(double a) {
this.a = a;
b = 0;
c = 0;
d = 0;
}
public Quaternion(double a, double b, double c, double d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
public Quaternion conjug() {
return new Quaternion(a, -b, -c, -d);
}
public double abs() {
return Math.
sqrt(a
* a
+ b
* b
+ c
* c
+ d
* d
); }
return Quaternion.divide(this.conjug(), this.abs() * this.abs());
}
public boolean isZero() {
return (a == 0 && b == 0 && c == 0 && d == 0);
}
public static Quaternion sum(Quaternion a, Quaternion b) {
return new Quaternion(a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d);
}
public static Quaternion sub(Quaternion a, Quaternion b) {
return new Quaternion(a.a - b.a, a.b - b.b, a.c - b.c, a.d - b.d);
}
public static Quaternion mul(Quaternion a, double mult) {
return new Quaternion(a.a * mult, a.b * mult, a.c * mult, a.d * mult);
}
public static Quaternion mul(Quaternion a, Quaternion b) {
return new Quaternion(a.a * b.a - a.b * b.b - a.c * b.c - a.d * b.d,
a.a * b.b + a.b * b.a + a.c * b.d - a.d * b.c,
a.a * b.c - a.b * b.d + a.c * b.a + a.d * b.b,
a.a * b.d + a.b * b.c - a.c * b.b + a.d * b.a);
}
return new Quaternion(a.a / divider, a.b / divider, a.c / divider, a.d / divider);
}
return Quaternion.mul(a, b.inverse());
}
((b
< 0)? " - " : " + ") + Math.
abs(b
) + "*i" + ((c
< 0)? " - " : " + ") + Math.
abs(c
) + "*j" + ((d
< 0)? " - " : " + ") + Math.
abs(d
) + "*k\n"); }
}
class Main {
public static void main
(String[] args
) { Quaternion qt1 = new Quaternion();
Quaternion qt2 = new Quaternion(5);
Quaternion qt3 = new Quaternion(1, 2, 3, 4);
Quaternion qt4 = new Quaternion(0.1, 1.4, -2.5, -1.7);
if (!qt1.isZero()) {
System.
out.
print(Quaternion.
sum(qt3, qt4
)); } else {
System.
out.
print(Quaternion.
mul(qt3, qt4
)); }
do {
qt2 = Quaternion.sub(qt2, qt3);
System.
out.
print(qt2.
conjug()); System.
out.
print(qt2.
inverse()); } while (qt2.isZero());
try {
System.
out.
print(Quaternion.
divide(qt3, qt4
)); System.
out.
print(e.
getMessage()); }
System.
out.
print(Quaternion.
mul(qt3,
17.2)); }
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBRdWF0ZXJuaW9uIHsKCXByaXZhdGUgZG91YmxlIGE7Cglwcml2YXRlIGRvdWJsZSBiOwoJcHJpdmF0ZSBkb3VibGUgYzsKCXByaXZhdGUgZG91YmxlIGQ7CgkKCXB1YmxpYyBRdWF0ZXJuaW9uKCkgewoJCWEgPSAwOwoJCWIgPSAwOwoJCWMgPSAwOwoJCWQgPSAwOwoJfQoJcHVibGljIFF1YXRlcm5pb24oZG91YmxlIGEpIHsKCQl0aGlzLmEgPSBhOwoJCWIgPSAwOwoJCWMgPSAwOwoJCWQgPSAwOwoJfQoJcHVibGljIFF1YXRlcm5pb24oZG91YmxlIGEsIGRvdWJsZSBiLCBkb3VibGUgYywgZG91YmxlIGQpIHsKCQl0aGlzLmEgPSBhOwoJCXRoaXMuYiA9IGI7CgkJdGhpcy5jID0gYzsKCQl0aGlzLmQgPSBkOwoJfQoJCglwdWJsaWMgUXVhdGVybmlvbiBjb25qdWcoKSB7CgkJcmV0dXJuIG5ldyBRdWF0ZXJuaW9uKGEsIC1iLCAtYywgLWQpOwoJfQoJcHVibGljIGRvdWJsZSBhYnMoKSB7CgkJcmV0dXJuIE1hdGguc3FydChhICogYSAgKyBiICogYiArIGMgKiBjICsgZCAqIGQpOwoJfQoJcHVibGljIFF1YXRlcm5pb24gaW52ZXJzZSgpIHRocm93cyBBcml0aG1ldGljRXhjZXB0aW9uIHsKCQlyZXR1cm4gUXVhdGVybmlvbi5kaXZpZGUodGhpcy5jb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