当前位置:网站首页>Leetcode 1952. Triple divisor

Leetcode 1952. Triple divisor

2022-06-11 10:31:00 I'm not xiaohaiwa~~~~

 Insert picture description here
Give you an integer n . If n There are exactly three positive divisors , return true ; otherwise , return false .

If there are integers k , Satisfy n = k * m , So integers m Namely n One of the Divisor .

Example 1:

 Input :n = 2
 Output :false
 explain :2  There are only two divisors :1  and  2 .

Example 2:

 Input :n = 4
 Output :true
 explain :4  There are three divisors :12  and  4 .
 

Tips :

  • 1 <= n <= 10^4

Code:

class Solution {
    
public:
    bool isThree(int n) {
    
        int res=0;
        for(int i=1;i<=n;i++)
        {
    
            if((n%i)==0)
                res++;
        }
        return res==3;
    }
};
原网站

版权声明
本文为[I'm not xiaohaiwa~~~~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111028393892.html