Prime numbers

Prime number A prime number is a natural number with exactly 2 distinct divisors. For example 2, 3, 5, 7 and so on. Given number N, How do we determine if it is prime? One approach is to iterate through the numbers [1, N] and count how many of them divide N. Can we check it faster than this? If prime number has only 2 divisors, that means it s divisible by only 1 and itself....

June 20, 2023 · 3 min · 457 words · Me

Power of number

Problem Find the answer obtained by raising A to the power of B, modulo the prime number 10^9+7. Here, A and B are both less than or equal to 10^13. We can find this using a simple loop. In other words, the number A is multiplied by B times, and we are talking about 10^13 times. How much action is that in general? A lot, and if you imagine that 300 million operations are performed in 1 second, then it will work for more than 9 hours....

April 15, 2023 · 5 min · 949 words · Me