### big-o

#### Complexity of Fermat's Little Theorem

Input: p > 2, a; 1 < a < p Output: Boolean: if p is a probable prime b = a**(p-1) if (b % p == 1){ return true; } else { return false; } So I'm thinking that the multiplication for b is log₂(a) * log₂(p-1), then the mod check is log₂(b)?

b = a ** (p-1) means ap-1. The complexity depends on the implementation of the exponentiation. In most cases I know, the simple power works by multiplying the basis with it's self as often as required. This results in something like O(log₂(a)⋅p). But if you use an implementation of the fast exponentiation method, you get indeed O(log₂(p)⋅log₂(p)) = O((log₂(p))²), since you can use modulo p after each step and so your resulting numbers never get bigger than p. Notice: The function returns true if p is prime or p is an Carmichael number.

### Related Links

Regarding time complexity, big O notation

O(log(n)) vs. O(log(n)^p)

Calculate Big-Oh and theta bound for the running time

Why this code gives big-O = O(1)

Confused on how to find c and k for big O notation if f(x) = x^2+2x+1

calculating complexity of a function

Big - O notation linear and binary search [closed]

Show the O-notation for the following code fragment

Big Theta Questions

Role of lower order terms in big O notation

Finding Big O notation

Which Big-O grows faster asymptotically

Total time complexity in a method

What complexity mutiplication table code here have?

what is the worst case time complexity of 5/n?

Big O notation of simple expressiosn [closed]