class Solution: def commonFactors(self, a: int, b: int) -> int: # ans 维护满足题意的公因子数 ans: int = 0 # a, b 的公因子必定是其最大公约数的因子 mx: int = gcd(a, b) # 枚举因子 [1, sqrt(mx)) factor: int = 1 # 这里不取等号是为了最后特殊处理恰好开平方的情况 while fa...
Given two positive integers a and b, return the number of common factors of a and b. An integer x is a common factor of a and b if x divides both a and b. Example 1: Input: a = 12, b = 6 Output: 4 Explanation: The common factors of 12 and 6 are 1, 2, 3, 6. Exampl...
Ideas of solving a problem When we do this problem, we should first think about how to extract the common factors.First, if a number is prime, the sum of its common factors cannot be equal to itself.If this number is 0, false is returned.If the number is not divisible by 2, such ...
Question: Write a program to find then-th ugly number. Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example,1, 2, 3, 4, 5, 6, 8, 9, 10, 12is the sequence of the first10ugly numbers. Note that1is typically treated as an ugly number. Analysis:...
Similar Problems:(E) Happy Number (E) Count Primes (M) Ugly Number II 回到顶部 2. 解题思路 回到顶部 3. 代码 classSolution {public:boolisUgly(intnum) {if(num <=0) {returnfalse; }while(0== num%2) { num= num/2; }while(0== num%3) ...