Advertisement
Guest User

Untitled

a guest
May 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. use num::complex::Complex;
  2. fn main() {
  3. fn prime(n: i64) -> bool {
  4. !(2..n).any(|i| n % i == 0)
  5. };
  6. let isprime = |a: Complex<i64>| match (a.re, a.im) {
  7. (0, _) => prime(a.im) && a.im.abs() % 4 == 3,
  8. (_, 0) => prime(a.re) && a.re.abs() % 4 == 3,
  9. _ => prime(a.re * a.re + a.im * a.im),
  10. };
  11. fn isunit(x: Complex<i64>) -> bool {
  12. match (x.re, x.im) {
  13. (0, 1) => true,
  14. (1, 0) => true,
  15. (0, -1) => true,
  16. (-1, 0) => true,
  17. _ => false,
  18. }
  19. }
  20. let mut a = Complex::new(27, 15);
  21. while !isunit(a) {
  22. for i in -27..27 {
  23. for j in -15..15 {
  24. let b = Complex::new(i, j);
  25. if isprime(b) {
  26. let c = a % b;
  27. if c.re == 0 && c.im == 0 {
  28. println!("{:?} / {:?}->{:?}", a, b, a/b);
  29. a /= b;
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement