Articles on Trending Technologies

Technical articles with clear explanations and examples

Find if a number is part of AP whose first element and difference are given using C++.

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 573 Views

Suppose we have the first element of AP, and the differenced. We have to check whether the given number n is a part of AP or not. If the first term is a = 1, differenced = 3, and the term x = 7 will be checked. The answer is yes.To solve this problem, we will follow these steps −If d is 0, and a = x, then return true, otherwise false.Otherwise, if d is not 0, then if x belongs to the sequence x = a + n * d, where n is a non-negative integer, only if (n ...

Read More

Find if two rectangles overlap using C++.

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

We know that a rectangle can be represented using two coordinates, the top left corner, and the bottom right corner. Suppose there are two rectangles, we have to check whether these two overlap or not. There are four coordinate points (l1, r1) and (l2, r2).l1 is the top-left corner of first rectangler1 is the bottom-right corner of the first rectanglel2 is the top-left corner of second rectangler2 is the bottom-right corner of the second rectangleWe have assumed that the rectangles are parallel to the coordinate axes. To solve this, we have to check a few conditions.One rectangle is above the ...

Read More

Find the multiple of x which is closest to a^b in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 181 Views

Suppose we have three integers, a, b and x. The task is to get the multiple of x, which is closest to ab. So if a = 5, b = 4 and x = 3, then output will be 624. As 54 = 625, and 624 is the multiple of 3, which is closest to 625.The task is simple. we have to follow these steps to solve this problem −calculate num := abThen find f := floor of (num/x)Now the closest element at the left will be cl = x * f, and at right will be cr = x ...

Read More

Find permutation of first N natural numbers that satisfies the given condition in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 294 Views

Suppose we have two integers N and K, and we have to find the permutation P of first N natural numbers such that there are exactly K elements which satisfies the condition GCD(P[i], i) > 1 for all 1

Read More

Find largest prime factor of a number using C++.

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Consider we have an element x, we have to find the largest prime factor of x. If the value of x is 6,  then-largest prime factor is 3. To solve this problem, we will just factorize the number by dividing it with the divisor of a number and keep track of the maximum prime factor.Example#include #include using namespace std; long long getMaxPrimefactor(long long n) {    long long maxPF = -1;    while (n % 2 == 0) {       maxPF = 2;       n /= 2;    }    for (int i = 3; i 2)    maxPF = n;    return maxPF; } int main() {    long long n = 162378;    cout

Read More

Find permutation of n which is divisible by 3 but not divisible by 6 in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 155 Views

Suppose we have a number n, and we have to find the permutation of this number, that is divisible by 3, but not divisible by 6. If no such value can be made, then return -1. For example, if n is 336, then the output can be 363.As we know a number is divisible by 6 means it is divisible by 3 and 2. So each even number that is divisible by 3, will be divisible by 6. If we interchange the digits of a number which is divisible by 3 and also even, to make it odd, it will ...

Read More

Perl First Program

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 451 Views

Interactive Mode ProgrammingYou can use Perl interpreter with -e option at the command line, which lets you execute Perl statements from the command line. Let's try something at $ prompt as follows −$perl -e 'print "Hello World"'This execution will produce the following result −Hello, worldScript Mode ProgrammingAssuming you are already on $ prompt, let's open a text file hello.pl using vi or vim editor and put the following lines inside your file.Example#!/usr/bin/perl # This will print "Hello, World" print "Hello, world";Here /usr/bin/perl is actual the Perl interpreter binary. Before you execute your script, be sure to change the mode of ...

Read More

Find prime number K in an array such that (A[i] % K) is maximum in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 180 Views

Suppose we have an array A with n integers. We have to find one element K such that K is prime, and A[i] mod K is maximum for all valid i among all possible values of K. If no such numbers are found, then return -1. For example, if A = [2, 10, 15, 7, 6, 8, 13], then the output will be 13. There are three prime numbers 2, 7, and 13. The maximum possible values of A[i] mod 2 is 1, (15 mod 2), for 7, it will be 6 mod 7 = 6, and for 13, it ...

Read More

Find product of prime numbers between 1 to n in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 404 Views

Suppose we have a number n. We have to find the product of prime numbers between 1 to n. So if n = 7, then output will be 210, as 2 * 3 * 5 * 7 = 210.We will use the Sieve of Eratosthenes method to find all primes. Then calculate the product of them.Example#include using namespace std; long PrimeProds(int n) {    bool prime[n + 1];    for(int i = 0; i

Read More

Comments in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 5K+ Views

Comments in any programming language are friends of developers. Comments can be used to make program user-friendly and they are simply skipped by the interpreter without impacting the core functionality. For example, in the above program, a line starting with hash # is a comment.Simply saying comments in Perl start with a hash symbol and run to the end of the line −# This is a comment in perlLines starting with = are interpreted as the start of a section of embedded documentation (pod), and all subsequent lines until the next =cut are ignored by the compiler. Following is the ...

Read More
Showing 28521–28530 of 61,297 articles
Advertisements