GCD!
InterviewTime limit1sMemory limit128 MB
For each pair n and k, compute gcd(n!, k); n can reach 1e9 so n! cannot be built, which forces a bound on the prime factors of k that matter.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
The greatest common divisor (GCD) of two natural numbers is the largest natural number that divides both of them without a remainder. For example, the greatest common divisor of and is , because is the largest integer that divides both and . (The common divisors of and are .)
The factorial of a natural number is the product of every positive integer less than or equal to it. For example, the factorial of is . (By definition, .)
Given two numbers and , write a program that computes the greatest common divisor of and . For example, if and , then .
Input
The input consists of several lines. Each line contains two integers and separated by a space, and the input continues until the end of the file. (, )
Output
For each line of the input, print the greatest common divisor of and on its own line.