Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use num::complex::Complex;
- fn main() {
- fn prime(n: i64) -> bool {
- !(2..n).any(|i| n % i == 0)
- };
- let isprime = |a: Complex<i64>| match (a.re, a.im) {
- (0, _) => prime(a.im) && a.im.abs() % 4 == 3,
- (_, 0) => prime(a.re) && a.re.abs() % 4 == 3,
- _ => prime(a.re * a.re + a.im * a.im),
- };
- fn isunit(x: Complex<i64>) -> bool {
- match (x.re, x.im) {
- (0, 1) => true,
- (1, 0) => true,
- (0, -1) => true,
- (-1, 0) => true,
- _ => false,
- }
- }
- let mut a = Complex::new(27, 15);
- while !isunit(a) {
- for i in -27..27 {
- for j in -15..15 {
- let b = Complex::new(i, j);
- if isprime(b) {
- let c = a % b;
- if c.re == 0 && c.im == 0 {
- println!("{:?} / {:?}->{:?}", a, b, a/b);
- a /= b;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement