diff --git a/Python/Count_Primes.py b/Python/Count_Primes.py new file mode 100644 index 0000000..133ac1d --- /dev/null +++ b/Python/Count_Primes.py @@ -0,0 +1,17 @@ +# https://leetcode.com/problems/count-primes/ + +class Solution: + def countPrimes(self, n: int) -> int: + prime = [True for i in range(n+1)] + p = 2 + while (p * p <= n): + if (prime[p] == True): + for i in range(p * p, n+1, p): + prime[i] = False + p += 1 + sol = 0 + for p in range(2, n): + if prime[p]: + sol += 1 + return sol + \ No newline at end of file diff --git a/Python/Simplified_Fractions.py b/Python/Simplified_Fractions.py new file mode 100644 index 0000000..c34f8c5 --- /dev/null +++ b/Python/Simplified_Fractions.py @@ -0,0 +1,17 @@ +# Link: https://leetcode.com/problems/simplified-fractions/submissions/ + +class Solution: + def simplifiedFractions(self, n: int): + def gcd(a, b): + if b == 0: + return a + return gcd(b, a % b) + sol = [] + for i in range(1, n + 1): + for j in range(1, i + 1): + if gcd(i, j) == 1: + if i == 1 and j == 1: + continue + ans = str(j) + '/' + str(i) + sol.append(ans) + return sol \ No newline at end of file