File tree 8 files changed +125
-10
lines changed
8 files changed +125
-10
lines changed Original file line number Diff line number Diff line change 11
11
"""
12
12
from __future__ import print_function
13
13
import math
14
- from decimal import *
14
+ from decimal import Decimal , getcontext
15
15
16
16
try :
17
17
raw_input # Python 2
@@ -33,7 +33,31 @@ def solution(n):
33
33
0
34
34
>>> solution(34)
35
35
44
36
+ >>> solution(3.4)
37
+ 2
38
+ >>> solution(0)
39
+ Traceback (most recent call last):
40
+ ...
41
+ ValueError: Parameter n must be greater or equal to one.
42
+ >>> solution(-17)
43
+ Traceback (most recent call last):
44
+ ...
45
+ ValueError: Parameter n must be greater or equal to one.
46
+ >>> solution([])
47
+ Traceback (most recent call last):
48
+ ...
49
+ TypeError: Parameter n must be int or passive of cast to int.
50
+ >>> solution("asd")
51
+ Traceback (most recent call last):
52
+ ...
53
+ TypeError: Parameter n must be int or passive of cast to int.
36
54
"""
55
+ try :
56
+ n = int (n )
57
+ except (TypeError , ValueError ) as e :
58
+ raise TypeError ("Parameter n must be int or passive of cast to int." )
59
+ if n <= 0 :
60
+ raise ValueError ("Parameter n must be greater or equal to one." )
37
61
getcontext ().prec = 100
38
62
phi = (Decimal (5 ) ** Decimal (0.5 ) + 1 ) / Decimal (2 )
39
63
Original file line number Diff line number Diff line change @@ -28,14 +28,38 @@ def isprime(no):
28
28
29
29
def solution (n ):
30
30
"""Returns the largest prime factor of a given number n.
31
-
31
+
32
32
>>> solution(13195)
33
33
29
34
34
>>> solution(10)
35
35
5
36
36
>>> solution(17)
37
37
17
38
+ >>> solution(3.4)
39
+ 3
40
+ >>> solution(0)
41
+ Traceback (most recent call last):
42
+ ...
43
+ ValueError: Parameter n must be greater or equal to one.
44
+ >>> solution(-17)
45
+ Traceback (most recent call last):
46
+ ...
47
+ ValueError: Parameter n must be greater or equal to one.
48
+ >>> solution([])
49
+ Traceback (most recent call last):
50
+ ...
51
+ TypeError: Parameter n must be int or passive of cast to int.
52
+ >>> solution("asd")
53
+ Traceback (most recent call last):
54
+ ...
55
+ TypeError: Parameter n must be int or passive of cast to int.
38
56
"""
57
+ try :
58
+ n = int (n )
59
+ except (TypeError , ValueError ) as e :
60
+ raise TypeError ("Parameter n must be int or passive of cast to int." )
61
+ if n <= 0 :
62
+ raise ValueError ("Parameter n must be greater or equal to one." )
39
63
maxNumber = 0
40
64
if isprime (n ):
41
65
return n
@@ -54,7 +78,6 @@ def solution(n):
54
78
elif isprime (i ):
55
79
maxNumber = i
56
80
return maxNumber
57
- return int (sum )
58
81
59
82
60
83
if __name__ == "__main__" :
Original file line number Diff line number Diff line change 6
6
e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
7
7
"""
8
8
from __future__ import print_function , division
9
- import math
10
9
11
10
try :
12
11
raw_input # Python 2
16
15
17
16
def solution (n ):
18
17
"""Returns the largest prime factor of a given number n.
19
-
18
+
20
19
>>> solution(13195)
21
20
29
22
21
>>> solution(10)
23
22
5
24
23
>>> solution(17)
25
24
17
25
+ >>> solution(3.4)
26
+ 3
27
+ >>> solution(0)
28
+ Traceback (most recent call last):
29
+ ...
30
+ ValueError: Parameter n must be greater or equal to one.
31
+ >>> solution(-17)
32
+ Traceback (most recent call last):
33
+ ...
34
+ ValueError: Parameter n must be greater or equal to one.
35
+ >>> solution([])
36
+ Traceback (most recent call last):
37
+ ...
38
+ TypeError: Parameter n must be int or passive of cast to int.
39
+ >>> solution("asd")
40
+ Traceback (most recent call last):
41
+ ...
42
+ TypeError: Parameter n must be int or passive of cast to int.
26
43
"""
44
+ try :
45
+ n = int (n )
46
+ except (TypeError , ValueError ) as e :
47
+ raise TypeError ("Parameter n must be int or passive of cast to int." )
48
+ if n <= 0 :
49
+ raise ValueError ("Parameter n must be greater or equal to one." )
27
50
prime = 1
28
51
i = 2
29
52
while i * i <= n :
Original file line number Diff line number Diff line change 17
17
def solution (n ):
18
18
"""Returns the smallest positive number that is evenly divisible(divisible
19
19
with no remainder) by all of the numbers from 1 to n.
20
-
20
+
21
21
>>> solution(10)
22
22
2520
23
23
>>> solution(15)
@@ -26,7 +26,31 @@ def solution(n):
26
26
232792560
27
27
>>> solution(22)
28
28
232792560
29
+ >>> solution(3.4)
30
+ 6
31
+ >>> solution(0)
32
+ Traceback (most recent call last):
33
+ ...
34
+ ValueError: Parameter n must be greater or equal to one.
35
+ >>> solution(-17)
36
+ Traceback (most recent call last):
37
+ ...
38
+ ValueError: Parameter n must be greater or equal to one.
39
+ >>> solution([])
40
+ Traceback (most recent call last):
41
+ ...
42
+ TypeError: Parameter n must be int or passive of cast to int.
43
+ >>> solution("asd")
44
+ Traceback (most recent call last):
45
+ ...
46
+ TypeError: Parameter n must be int or passive of cast to int.
29
47
"""
48
+ try :
49
+ n = int (n )
50
+ except (TypeError , ValueError ) as e :
51
+ raise TypeError ("Parameter n must be int or passive of cast to int." )
52
+ if n <= 0 :
53
+ raise ValueError ("Parameter n must be greater or equal to one." )
30
54
i = 0
31
55
while 1 :
32
56
i += n * (n - 1 )
@@ -39,7 +63,6 @@ def solution(n):
39
63
if i == 0 :
40
64
i = 1
41
65
return i
42
- break
43
66
44
67
45
68
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -36,7 +36,31 @@ def solution(n):
36
36
229
37
37
>>> solution(100)
38
38
541
39
+ >>> solution(3.4)
40
+ 5
41
+ >>> solution(0)
42
+ Traceback (most recent call last):
43
+ ...
44
+ ValueError: Parameter n must be greater or equal to one.
45
+ >>> solution(-17)
46
+ Traceback (most recent call last):
47
+ ...
48
+ ValueError: Parameter n must be greater or equal to one.
49
+ >>> solution([])
50
+ Traceback (most recent call last):
51
+ ...
52
+ TypeError: Parameter n must be int or passive of cast to int.
53
+ >>> solution("asd")
54
+ Traceback (most recent call last):
55
+ ...
56
+ TypeError: Parameter n must be int or passive of cast to int.
39
57
"""
58
+ try :
59
+ n = int (n )
60
+ except (TypeError , ValueError ) as e :
61
+ raise TypeError ("Parameter n must be int or passive of cast to int." )
62
+ if n <= 0 :
63
+ raise ValueError ("Parameter n must be greater or equal to one." )
40
64
primes = []
41
65
num = 2
42
66
while len (primes ) < n :
Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ def solution():
28
28
if (a ** 2 ) + (b ** 2 ) == (c ** 2 ):
29
29
if (a + b + c ) == 1000 :
30
30
return a * b * c
31
- break
32
31
33
32
34
33
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -61,4 +61,4 @@ def solution():
61
61
62
62
63
63
if __name__ == "__main__" :
64
- print (solution (171 ))
64
+ print (solution ())
Original file line number Diff line number Diff line change @@ -40,7 +40,6 @@ def solution(n):
40
40
semidivisible = []
41
41
for x in range (n ):
42
42
l = [i for i in input ().split ()]
43
- c1 = 0
44
43
c2 = 1
45
44
while (1 ):
46
45
if len (fib (l [0 ],l [1 ],c2 ))< int (l [2 ]):
You can’t perform that action at this time.
0 commit comments