Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Check whether the given number is Euclid Number or not in Python
A Euclid number is an integer that can be represented as the product of the first n prime numbers plus 1. In mathematical terms, a Euclid number follows the formula: En = Pn + 1 where Pn is the product of the first n prime numbers. For example, 211 is a Euclid number because it can be expressed as (2×3×5×7) + 1 = 210 + 1 = 211. Algorithm To check if a number is a Euclid number, we need to ? Generate all prime numbers up to a reasonable limit using the Sieve ...
Read MoreCheck whether the frequencies of all the characters in a string are prime or not in Python
Sometimes we need to check whether the frequencies of all characters in a string are prime numbers. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. So, if the input is like s = "apuuppa", then the output will be True as there are two 'a's, three 'p's and two 'u's. Since 2 and 3 are prime numbers, all character frequencies are prime. Algorithm To solve this problem, we will follow these steps − Create a frequency map containing all characters and their counts ...
Read MoreCheck whether the Average Character of the String is present or not in Python
When working with strings in Python, you might need to find the "average character" based on ASCII values. This involves calculating the average of all character ASCII values and determining if that average corresponds to an actual character in the string. The average character is found by taking the floor of the average ASCII values of all characters in the string. If this average ASCII value corresponds to a character present in the original string, we return that character. Example Let's say we have the string s = "pqrst". The ASCII values are: p = ...
Read MoreCheck whether sum of digits at odd places of a number is divisible by K in Python
In this problem, we need to check whether the sum of digits at odd positions (counting from right to left) of a number is divisible by a given value k. The positions are counted starting from 1. So, if the input is like n = 2416 and k = 5, then the output will be True. The digits at odd positions from right to left are: position 1 (digit 6) and position 3 (digit 4). Their sum is 4 + 6 = 10, which is divisible by 5. Algorithm To solve this problem, we will follow these ...
Read MoreCheck whether second string can be formed from characters of first string in Python
Suppose we have two strings s and t. We have to check whether t can be formed using characters of s or not. So, if the input is like s = "owleh" t = "hello", then the output will be True. Algorithm To solve this, we will follow these steps ? freq := a map containing all characters and their frequencies for i in range 0 to size of t - 1, do ...
Read MoreCheck if a number can be expressed as a^b in Python
Sometimes we need to check if a number can be expressed as a power of another number, i.e., whether we can write it as a^b where both a and b are positive integers. So, if the input is like 125, then the output will be True as 125 = 5^3, so a = 5 and b = 3. Algorithm To solve this, we will follow these steps − If num is same as 1, then return True (since 1 = 1^1) For each potential base i from 2 to √num: Calculate val = log(num) ...
Read MoreCheck whether product of integers from a to b is positive, negative or zero in Python
When we need to determine the sign of a product of integers in a range [a, b], we don't need to calculate the actual product. Instead, we can use mathematical rules to determine if the result will be positive, negative, or zero. So, if the input is like a = -8, b = -2, then the output will be Negative, as the values in that range are [-8, -7, -6, -5, -4, -3, -2], and the product is -40320 which is negative. Algorithm To solve this efficiently, we follow these steps: If both a and ...
Read MoreCheck whether product of digits at even places of a number is divisible by K in Python
Sometimes we need to check if the product of digits at even positions (counting from right to left) of a number is divisible by another number. In this problem, the rightmost digit is at position 1, the next digit is at position 2, and so on. For example, in the number 59361, the digits at even positions are 6 (position 2), 9 (position 4), making the product 6 × 9 = 54. If we need to check divisibility by 3, then 54 ÷ 3 = 18, so it's divisible. Algorithm To solve this problem, we follow these ...
Read MoreCheck whether product of \'n\' numbers is even or odd in Python
In this article, we explore different methods to check whether the product of n numbers is even or odd. A number that is divisible by 2 is known as an even number, otherwise it is an odd number. For example, 14 and 12 are two even numbers, their product 168 is even. Numbers 9 and 5 are odd, their product 45 is odd. Consider one even number 2 and one odd number 3 − their product 6 is even. Mathematical Facts Understanding these mathematical rules helps us determine if a product is even or odd − ...
Read MoreCheck whether N is a Dihedral Prime Number or not in Python
A Dihedral Prime Number is a number that remains prime when viewed on a 7-segment display in normal orientation and when rotated 180 degrees (upside down). The number must contain only digits that look the same when rotated: 0, 1, 2, 5, and 8. For example, if we have n = 1181, it appears as 1881 when rotated upside down (since 2 becomes 5 and 5 becomes 2), and both numbers are prime. Normal: 1181 Rotate 180° Upside down: ...
Read More