-
Notifications
You must be signed in to change notification settings - Fork 7
/
leetcode263_1.py
70 lines (67 loc) · 1.71 KB
/
leetcode263_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# from __future__ import division
import sys
# class Solution(object):
# def isPrime(self,num):
# for x in range(2,int(num**(1/2)+1)):
# if num%x==0:
# return False
# return True
# def primeFactors(self,num):
# if num<0:
# res=[1,-1]
# num*=-1
# else:
# res=[1]
# if self.isPrime(num):
# res.append(num)
# cnum=num
# for x in range(2,int(num/2)+1):
# if cnum%x==0 and self.isPrime(x):
# res.append(x)
# cnum/=x
# return res
# def isUgly(self, num):
# """
# :type num: int
# :rtype: bool
# """
# pF=set(self.primeFactors(num))
# print(pF)
# ourSet=set([1,2,3,5])
# if len(pF-ourSet)==0:
# return True
# return False
import math
class Solution(object):
def isPrime(self,num):
for x in range(2,int(math.ceil(num/2))+1):
if num%x==0:
return False
return True
def primeFactors(self,num):
if num<0:
res=[1,-1]
num*=-1
else:
res=[1]
if self.isPrime(num):
res.append(num)
cnum=num
for x in range(2,int(num/2)+1):
if cnum%x==0 and self.isPrime(x):
res.append(x)
cnum/=x
return res
def isUgly(self, num):
"""
:type num: int
:rtype: bool
"""
pF=set(self.primeFactors(num))
print(pF)
ourSet=set([1,2,3,5])
if len(pF-ourSet)==0:
return True
return False
print(Solution().isUgly(6),2/3)
print(sys.version)