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 the value of f(n) / f(r) * f(n-r)
- 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 2^(2^A) % B
- Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n
- Find two numbers whose sum and GCD are given
- Find the sum of all multiples of 2 and 5 below N
- Find the value of ln(N!) using Recursion
- Find two integers A and B such that A ^ N = A + N and B ^ N = B + N
- Find x, y, z that satisfy 2/n = 1/x + 1/y + 1/z
- Given two numbers a and b find all x such that a % x = b
- Find the value of N when F(N) = f(a)+f(b) where a+b is the minimum possible and a*b = N
- Find (a^b)%m where 'a' is very large
- Find x and y satisfying ax + by = n
- Find the other number when LCM and HCF given
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.