Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Print the prime factorization of the greatest common divisor of two numbers

Title says it all. Two input 32-bit positive integers m, n >= 2, output gcd(m,n) in prime factorization form.

Input

Command line args or 1 line of stdin okay, whatever's better for golf.

Output

Single space delimited with exponents (no additional spaces). Output nothing if the inputs are relatively prime.

Examples:

$ ./factorize 96 162
2^1 3^1
$ ./factorize 14 15
$ ./factorize 196 294
2^1 7^2

Rules

  • You may not use external resources, math libraries or built-in functions for factorization or GCD. Examples: Java, no java.lang.Math. ruby, no prime_division, perl, no factor, etc.

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ ⊎ is a symbol in perl? I didn't know that. \$\endgroup\$ Commented May 11, 2014 at 16:27
  • \$\begingroup\$ @durron597 Only Perl 6 :) \$\endgroup\$ Commented May 11, 2014 at 16:31

AltStyle によって変換されたページ (->オリジナル) /