File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ int countTriples (int n)
4+ {
5+ int res = 0 ;
6+ for (int a = 1 ;a<=n;++a)
7+ {
8+ for (int b = 1 ;b<=n;++b)
9+ {
10+ int c = sqrt (a*a + b*b+1.0 );
11+ if (c<=n&&c*c == a*a + b*b)
12+ {
13+ ++res;
14+ }
15+ }
16+ }
17+ return res;
18+ }
19+ };
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def countTriples (self ,n :int )-> int :
3+ ans = 0
4+ for a in range (1 ,n + 1 ):
5+ for b in range (1 ,a ):
6+ if a * a + b * b > n * n :
7+ break
8+ c2 = a * a + b * b
9+ if iSqrt (c2 )** 2 == c2 :
10+ ans += 1
11+
12+ return ans * 2
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ bool isUgly (int n) {
4+ if (n<= 0 )
5+ return false ;
6+ while (n%3 == 0 )
7+ {
8+ n /=3 ;
9+ }
10+ while (n%5 == 0 )
11+ {
12+ n/=5 ;
13+ }
14+ return (n & (n-1 )) == 0 ;
15+ }
16+ };
Original file line number Diff line number Diff line change 1+ var factors = []int {2 ,3 ,5 }
2+
3+ func isUgly (n int ) bool {
4+ if n <= 0 {
5+ return false
6+ }
7+ for _ ,f := range factors {
8+ for n % f == 0 {
9+ n /= f
10+ }
11+ }
12+ return n == 1
13+ }
You can’t perform that action at this time.
0 commit comments