WebInput: First line of the input file contains two integers, a and b. Output: Print the number of common factors of a and b. Constraints: SAMPLE INPUT 10 15 SAMPLE OUTPUT 2 Explanation The common factors of and are 1 and 5. Time Limit: 1.0 sec (s) for each input file. Memory Limit: 256 MB Source Limit: 1024 KB WebMay 21, 2024 · Just to have a more readable (than the answer by @Justin) and complete (than the answer by @Sedsarq) version of the algorithm presented in the other answers, here is a version that keeps the factors in a set and uses the fact that factors always come in pairs:. from math import sqrt def get_factors(n): """Returns a sorted list of all unique …
Python Count of common elements in the lists
WebMay 15, 2024 · For Example. Input − x = 10 y = 20 Output − Common prime factor of two numbers are: 2 5. Explanation − common primes factors between 10 and 20 are 2 and 5 only. Input − x = 34 y = 12 Output − Common prime factor of two numbers are: 2. Explanation − common primes factors between 34 and 12 are 2. WebJun 23, 2024 · Solution: The factors are the numbers that are a number’s exact divisors. There are some steps to take in order to identify the common factors. Step 1 : Separately write down all the factors of the given numbers. Step 2 : Now look for the factors that are common in the given numbers and write them down in a separate row. pattam pole
Program to count number of common divisors of two numbers in Python
WebSep 2, 2024 · Method #2 : Using sum () + map () + eq The task performed in above method using zip () can be executed here using the map function which performs similar task. … to find the factors which are common for two numbers , do. def cf(num1,num2): n=[] for i in range(1, min(num1, num2)+1): if num1%i==num2%i==0: n.append(i) return n print(cf(6,12)) >> output [1, 2, 3, 6] edit: if you want the number of common factors . print(len(cf(6,12))) >> output 4 WebThe Python program is as follows- num1 = int(input("ENTER FIRST NUMBER : ")) num2 = int(input("ENTER SECOND NUMBER : ")) divisor = 0 print("THE COMMON DIVISORS OF NUMBER ",num1," AND ",num2," ARE -") for i in range(1,min(num1,num2)+1): if num1%i == num2%i == 0: divisor = i print(divisor) Python program output pattampoochi 2022 download