Knowee
Questions
Features
Study Tools

Problem StatementWrite a program to check if the given two numbers M and N are friendly pairs or not. Friendly pair(Amicable numbers) are two different numbers related in a way such that the Ratio’s sum of the proper divisors divided by the number itself for each is the same.Example 1Input: M = 6 N = 28Output: (6, 28) are friendly pairsExplanation: Sum of divisors of 6 is 1 + 2 + 3 = 6, 28 is 1 + 2 + 4 + 7 + 14 = 28. Both sums divided by the numbers are 1.Example 2Input: M = 10 N = 20Output: (10, 20) are not friendly pairsExplanation: Sum of divisors of 10 is 1 + 2 + 5 = 8, 20 is 1 + 2 + 4 + 5 + 10 = 22. The ratios 8/10 and 22/20 are different.Your task: Write the call-by-reference function getDivisorsSum() which takes an integer M and N as input parameters, and returns the sum of its divisors. Check whether M and N are friendly pairs or not.Note: This question was asked in the Accenture coding tests.Input format :The input consists of two integers M and N.Output format :If the condition is met, the output prints "(M, N) are friendly pairs" where M and N are entered integers.Otherwise, the output prints "(M, N) are not friendly pairs" where M and N are entered integers.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:-104 ≤ M, N ≤ 104Sample test cases :Input 1 :30 40Output 1 :(30, 40) are friendly pairsInput 2 :-30 40Output 2 :(-30, 40) are not friendly pairsInput 3 :6 28Output 3 :(6, 28) are friendly pairsInput 4 :10 20Output 4 :(10, 20) are not friendly pa

Question

Problem StatementWrite a program to check if the given two numbers M and N are friendly pairs or not. Friendly pair(Amicable numbers) are two different numbers related in a way such that the Ratio’s sum of the proper divisors divided by the number itself for each is the same.Example 1Input: M = 6 N = 28Output: (6, 28) are friendly pairsExplanation: Sum of divisors of 6 is 1 + 2 + 3 = 6, 28 is 1 + 2 + 4 + 7 + 14 = 28. Both sums divided by the numbers are 1.Example 2Input: M = 10 N = 20Output: (10, 20) are not friendly pairsExplanation: Sum of divisors of 10 is 1 + 2 + 5 = 8, 20 is 1 + 2 + 4 + 5 + 10 = 22. The ratios 8/10 and 22/20 are different.Your task: Write the call-by-reference function getDivisorsSum() which takes an integer M and N as input parameters, and returns the sum of its divisors. Check whether M and N are friendly pairs or not.Note: This question was asked in the Accenture coding tests.Input format :The input consists of two integers M and N.Output format :If the condition is met, the output prints "(M, N) are friendly pairs" where M and N are entered integers.Otherwise, the output prints "(M, N) are not friendly pairs" where M and N are entered integers.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:-104 ≤ M, N ≤ 104Sample test cases :Input 1 :30 40Output 1 :(30, 40) are friendly pairsInput 2 :-30 40Output 2 :(-30, 40) are not friendly pairsInput 3 :6 28Output 3 :(6, 28) are friendly pairsInput 4 :10 20Output 4 :(10, 20) are not friendly pa

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python solution for the problem:

def getDivisorsSum(num):
    sum = 0
    for i in range(1, num):
        if num % i == 0

Similar Questions

You are given 2 integer arrays nums1 and nums2 of lengths n and m respectively. You are also given a positive integer k.A pair (i, j) is called good if nums1[i] is divisible by nums2[j] * k (0 <= i <= n - 1, 0 <= j <= m - 1).Return the total number of good pairs. Example 1:Input: nums1 = [1,3,4], nums2 = [1,3,4], k = 1Output: 5Explanation:The 5 good pairs are (0, 0), (1, 0), (1, 1), (2, 0), and (2, 2).Example 2:Input: nums1 = [1,2,4,12], nums2 = [2,4], k = 3Output: 2Explanation:The 2 good pairs are (3, 0) and (3, 1). Constraints:1 <= n, m <= 1051 <= nums1[i], nums2[j] <= 1061 <= k <= 103C++ 1class Solution {2public:3    long long numberOfPairs(vector<int>& nums1, vector<int>& nums2, int k) {4        5   }6};

ou are given an array of integers of length n. Determine the number of pairs of adjacent elements whose sum is divisible by a given integer k. If such pairs exist, output the count of pairs; otherwise, indicate that no pairs were found.Example 1Input:3 // number of elements (n)10 2 30 // elements2 // kOutput: Number of pairs: 2Explanation: In the given array [10, 2, 30], the pairs with sums divisible by 2 are (10, 2) and (2, 30). Hence, the output is 2, indicating the number of such pairs found.Input format :The first line consists of an integer n, representing the size of the array.The second line consists of n space-separated integers, representing the elements of the array.The third line consists of an integer k, representing the divisor.Output format :If there exist pairs of adjacent elements in the array whose sum is divisible by k, output "Number of pairs: " followed by the count of such pairs.If no such pairs are found, output "No pairs found".Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases will fall under the following constraints:3 ≤ n ≤ 251 ≤ Each element ≤ 1002 ≤ k ≤ 25Sample test cases :Input 1 :310 2 302Output 1 :Number of pairs: 2Input 2 :610 20 30 40 50 6010

Problem Statement:Given a number check whether the number is deficient number or not.DEFICIENT NUMBER :  A deficient number or defective number  is a number for which the sum of proper divisors is less than n. For example, the proper divisors of 8 are 1, 2, and 4, and their sum is less than 8, so 8 is deficientInput Format:Given an integer n .Output Format:Print Yes if it is a deficient number or No .Sample Input 1:8Sample Output 1:YesSample Input 2:6Sample Output 2:No

Problem StatementAnna is working on a program to find common factors of two unsigned integers. Design a program that:Takes two unsigned integers: n1 and n2, as input.Identifies and prints all common factors of these numbers.For example, Let us take two numbers 24 and 36. The factors of 24 are 1, 2, 3, 4, 6, 8, 12, 24. The factors of 36 are 1, 2, 3, 4, 6, 9, 12, 36. The common factors of 24 & 36 are 1,2,3,4,6,12 Ensure the program accurately identifies common factors, providing correct results for various inputs.Input format :The input consists of two unsigned integers n1 and n2 separated by a space.Output format :The output prints the common factors of n1 and n2, separated by a space.

The extended Euclid’s algorithm determines not only the greatest commondivisor d of two positive integers m and n but also integers (not necessarilypositive) x and y, such that mx + ny = d.a. Look up a description of the extended Euclid’s algorithm (see, e.g., [KnuI,p. 13]) and implement it in the language of your choice.b. Modify your program to find integer solutions to the Diophantine equationax + by = c with any set of integer coefficients a, b, and c

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.