Posts

Showing posts with the label math

1819. Number of Different Subsequences GCDs (Leetcode)

Blog You are given an array nums that consists of positive integers. The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly. For example, the GCD of the sequence [4,6,16] is 2 . A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array. For example, [2,5,10] is a subsequence of [1,2,1,2,4,1,5,10] . Return the number of different GCDs among all non-empty subsequences of nums . Example: 1 Input: nums = [6,10,3] Output: 5 Example: 2 Input: nums = [5,15,40,5,6] Output: 7 ...

1814. Count Nice Pairs in an Array

Blog You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x . For example, rev(123) = 321 , and rev(120) = 21 . A pair of indices (i, j) is nice if it satisfies all of the following conditions: 0 nums[i] + rev(nums[j]) == nums[j] + rev(nums[i]) Return the number of nice pairs of indices. Since that number can be too large, return it modulo 10 9 + 7 . Example: 1 Input: nums = [42,11,1,97] Output: 2 Example: 2 Input: nums = [13,10,35,24,76] Output: 4 Constraints: 1 0 Step I (Cha...

1808. Maximize Number of Nice Divisors (Leetcode)

Blog You are given a positive integer primeFactors . You are asked to construct a positive integer n that satisfies the following conditions: The number of prime factors of n (not necessarily distinct) is at most primeFactors . The number of nice divisors of n is maximized. Note that a divisor of n is nice if it is divisible by every prime factor of n . For example, if n = 12 , then its prime factors are [2,2,3] , then 6 and 12 are nice divisors, while 3 and 4 are not. Return the number of nice divisors of n . Since that number can be too large, return it modulo 10 9 + 7. Note that a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The prime factors of a number n is a list of prime numbers such that thei...

1798. Maximum Number of Consecutive Values You Can Make (Leetcode)

Blog You are given an integer array coins of length n which represents the n coins that you own. The value of the i th coin is coins[i] . You can make some value x if you can choose some of your n coins such that their values sum up to x . Return the maximum number of consecutive integer values that you can make with your coins starting from and including 0 . Note that you may have multiple coins of the same value. Example: 1 Input: coins = [1,3] Output: 2 Example: 2 Input: coins = [1,1,1,4] Output: 8 Example: 3 Input: [1,4,10,3,1] Output: 20 Constraints: ...