Given a very large number N. The task is to find (1n + 2n + 3n + 4n) mod 5.
Input: N = 4
(1 + 16 + 81 + 256) % 5 = 354 % 5 = 4
Input: N = 7823462937826332873467731
Approach: (1n + 2n + 3n + 4n) mod 5 = (1n mod ?(5) + 2n mod ?(5) + 3n mod ?(5) + 4n mod ?(5)) mod 5.
This formula is correct because 5 is a prime number and it is coprime with 1, 2, 3, 4.
Know about ?(n) and modulo of large number
?(5) = 4, hence (1n + 2n + 3n + 4n) mod 5 = (1n mod 4 + 2n mod 4 + 3n mod 4 + 4n mod 4) mod 5
Below is the implementation of the above approach:
- Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n
- Find K such that |A - K| = |B - K|
- Find 2^(2^A) % B
- Find the value of f(n) / f(r) * f(n-r)
- Find N from the value of N!
- Find the value of max(f(x)) - min(f(x)) for a given F(x)
- Find value of (1^n + 2^n + 3^n + 4^n ) mod 5
- Find (a^b)%m where 'b' is very large
- Find two numbers from their sum and XOR
- Find if the Vacation can be taken or not
- Find Kth smallest value for b such that a + b = a | b
- Find the ln(X) and log10X with the help of expansion
- Find two integers A and B such that A ^ N = A + N and B ^ N = B + N
- Find (a^b)%m where 'a' is very large
- Program to find value of 1^k + 2^k + 3^k + ... + n^k
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.