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 value of (1^n + 2^n + 3^n + 4^n ) mod 5
- Find 2^(2^A) % B
- Find K such that |A - K| = |B - K|
- Find N from the value of N!
- Find the value of max(f(x)) - min(f(x)) for a given F(x)
- Find the value of f(n) / f(r) * f(n-r)
- Find if the Vacation can be taken or not
- Find the sum of the series x(x+y) + x^2(x^2+y^2) +x^3(x^3+y^3)+ ... + x^n(x^n+y^n)
- Find x, y, z that satisfy 2/n = 1/x + 1/y + 1/z
- Find two integers A and B such that A ^ N = A + N and B ^ N = B + N
- Find F(n) when F(i) and F(j) of a sequence are given
- Find (a^b)%m where 'a' is very large
- Program to find value of 1^k + 2^k + 3^k + ... + n^k
- Find N values of X1, X2, ... Xn such that X1 < X2 < ... < XN and sin(X1) < sin(X2) < ... < sin(XN)
- Find the ln(X) and log10X with the help of expansion
- Find the sum of series 3, 7, 13, 21, 31....
- Find sum of the series 1-2+3-4+5-6+7.......
- Find gcd(a^n, c) where a, n and c can vary from 1 to 10^9
- 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.