Tag: math
Fermat Prime Test Algorithm is to check whether a number is prime. It is a probabilistic approach that based on the following observation. . This is also known as …
The problem is from codeforces: http://www.codeforces.com/problemset/problem/245/E The minimal number of people can be obtained by greedy approach, assuming that at each possible cases, the same people entered and left …
If we want to compute , we can have a naive implementation by multiplication of base number x. def pow(x, n): r = 1 for _ in xrange(n): r *= …
In , the GCD (Greatest Common Divisor) is given in brief details. The algorithm can be implemented in both recursive and iterative forms. The recursive formula is , and …
The problem is from codeforces: http://codeforces.com/problemset/problem/245/A A really simple math problem, can be solved within a few lines of Python code: #!/usr/bin/env python ax = asum = 0 bx = …