Hafeezul Kareem

Hafeezul Kareem

259 Articles Published

Articles by Hafeezul Kareem

Page 15 of 26

Find (a^b)%m where 'a' is very large in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 318 Views

In this tutorial, we are going to solve the equation (ab)%m where a is a very large number.The equation (ab)%m=(a%m)*(a%m)...b_times. We can solve the problem by finding the value of a%m and then multiplying it b times.Let's see the steps to solve the problem.Initialize the numbers a, b, and m.Write a function to find the a%m.Initialize the number with 0.Iterate over the number in string format.Add the last digits to the number.Update the number with number modulo them.Get the value of a%m.Write a loop that iterates b times.Multiply the a%m and modulo the result with m.Print the result.ExampleLet's see the ...

Read More

Find A and B from list of divisors in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 214 Views

In this tutorial, we are going to solve the below problem.Given an array of integers, we have to find two numbers A and B. All the remaining numbers in the array are the divisors of A and B.If a number is a divisor of both A and B, then it will present twice in the array.Let's see the steps to solve the problem.The max number in the array is one of the numbers from A and B. Let's say it is A.Now, B will be the second-largest number or the number which is not a divisor of A.ExampleLet's see the ...

Read More

Find 2^(2^A) % B in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 177 Views

In this tutorial, we are going to write a program to evaluate the equation 2^(2^A) % B.We are going to find the value of the equation using a recursive function. Let's see the steps to solve the problem.Write a recursive function that takes 2 arguments A and B.If A is 1, then return 4 % B as 2^(2^1) % B = 4 % B.Else recursively call the function with A-1 and b.Return the result^2%B.Print the solutionExampleLet's see the code.#include using namespace std; long long solveTheEquation(long long A, long long B) {    // 2^(2^1) % B = 4 % ...

Read More

Find (1^n + 2^n + 3^n + 4^n) mod 5 in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 319 Views

In this tutorial, we are going to solve the following problem.Given an integer n, we have to find the (1n+2n+3n+4n)%5The number (1n+2n+3n+4n) will be very large if n is large. It can't be fit in the long integers as well. So, we need to find an alternate solution.If you solve the equation for the number 1, 2, 3, 4, 5, 6, 7, 8, 9 you will get 10, 30, 100, 354, 1300, 4890, 18700, 72354, 282340 values respectively.Observe the results of the equation carefully. You will find that the last digit of the equation result repeats for every 4th number. ...

Read More

Find a number that divides maximum array elements in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 255 Views

In this tutorial, we are going to find the number that is divided into maximum elements in the given array.Let's see the steps to solve the problem.Initialize the array and a variable to store the result.Iterate over the array.Initialize the counter variable.Iterate over the array again.Increment the counter if the current element is divisible by the array element.Update the result if the current count is maximum.Print the result.ExampleLet's see the code.#include using namespace std; int numberWithMaximumMultiples(int arr[], int n) {    int result = -1;    for (int i = 0; i < n; i++) {       ...

Read More

Find a Number X whose sum with its digits is equal to N in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 265 Views

In this tutorial, we are going to find a number whose some including with its digits is equal to the given number N.The idea is simple, we are going to check the left and right 100 numbers of the given number. It won't lie out that bound as N ≤ 1000000000 and the sum won't exceed 100.Let's see the steps to solve the problem.Initialize the number.Write a loop that iterates 100 times.Get the n - i and n + i values.Find the sum of the digits and add them.If anyone of them is equal to the N, print them.ExampleLet's see ...

Read More

Find a partition point in array in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 479 Views

In this tutorial, we are going to find the partition point in an array where all the elements left to the partition point are small and all the elements right to the partition point are large.Let's see the steps to solve the problem.Initialize the array.Iterate over the array.Iterate from 0 to I and check each value whether it is smaller than the current value or not.Iterate from I to n and check each value whether it is larger than the current value or not.If the bot the conditions satisfied, then return the value.Print the partition point.ExampleLet's see the code.#include ...

Read More

Find a peak element in a 2D array in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 464 Views

In this tutorial, we are going to write a program that finds the peak element in a 2D array.An element is called a peak element if all the elements around it are smaller than the element.Let's see the steps to solve the problem.Initialize the 2D array with dummy data.Iterate over the 2D array.First, check the corner elements of the 2D array.Next, write the conditions for the first and last rows of the 2D array.Now, check for the first and last columns of the 2D array.And finally, check the middle elements.In each case, we have to compare the current element with ...

Read More

Find a peak element in Linked List in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 432 Views

In this tutorial, we are going to write a program that finds the peak element in the given linked list.The peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Check for the base cases like whether the linked list is empty or of length 1.Store the first element in a variable called previous.Iterate over the linked list.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Update the ...

Read More

Find a peak element in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 409 Views

In this tutorial, we are going to write a program that finds the peak element in the given arrayThe peak element is an element that is greater than the surrounding elements. Let's see the steps to solve the problem.Initialize the array with dummy data.Check for the first element and last element for the peak element condition.Iterate over the array from the second element.Check whether the current element is greater than the previous element and the next element.Return if the above condition satisfies.Print the resultExampleLet's see the code.#include using namespace std; int findPeakElement(int arr[], int n) {    if (n ...

Read More
Showing 141–150 of 259 articles
« Prev 1 13 14 15 16 17 26 Next »
Advertisements