Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added Maths Section#36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kehsihba19 wants to merge2 commits intoOmkarPathak:master
base:master
Choose a base branch
Loading
fromkehsihba19:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletionsMaths/catalan.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
def catalan(n):
if (n == 0 or n == 1):
return 1
catalan = [0]*(n+1)
catalan[0] = 1
catalan[1] = 1
for i in range(2, n + 1):
catalan[i] = 0
for j in range(i):
catalan[i] = catalan[i] + catalan[j] * catalan[i-j-1]
return catalan[n]

print("Enter value of n:")
a=int(input())
print(f"Catalan Number(nth) is : {catalan(a)}")
18 changes: 18 additions & 0 deletionsMaths/check_prime.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
def check(n):
if(n==1):
return False
if(n==2 or n==3):
return True
i=2
while i*i<=n:
if(n%i==0):
return False
i+=1
return True

print("Enter number :")
a=int(input())
if(check(a)):
print(f"{a} is a prime number")
else:
print(f"{a} is not a prime number")
9 changes: 9 additions & 0 deletionsMaths/gcd.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
def computeGCD(x, y):
while(y):
x, y = y, x % y

return x

print("Enter two numbers:")
a,b=map(int,input().split())
print(f"Gcd of {a} and {b} is {computeGCD(a,b)}")
21 changes: 21 additions & 0 deletionsMaths/prime_factors.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
def prime_factors(n):
i=2
ans=[]
while i*i<=n:
if(n%i==0):
ans.append(i)
while(n%i==0):
n=n//i
i+=1
if(n!=1):
ans.append(n)
if(len(ans)==0):
print("No prime factors")
else:
print("Prime factors are : ",end=" ")
print(*ans)


print("Enter number:")
a=int(input())
prime_factors(a)
18 changes: 18 additions & 0 deletionsMaths/sieve.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
def sieve(n):
prime=[1]*(n+1)
prime[0],prime[1]=0,0
i=2
while i*i<=n:
if(prime[i]):
for j in range(i*i,n+1,i):
prime[j]=0
i+=1
print("Primes are : ")
for i in range(0,n+1):
if(prime[i]):
print(i,end=" ")
print()

print("Enter upper bound of prime:")
a=int(input())
sieve(a)
10 changes: 10 additions & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,16 @@ Pune, Maharashtra, India.<br />
* [Finding the length of linked list](Linked%20Lists/P01_FindingLengthOfLinkedList.py)
* [Reversing the linked list](Linked%20Lists/P02_ReversingLinkedList.py)

# Maths

* [Maths Concept](Maths)
* [Catalan Number](Maths/catalan.py)
* [Check Prime](Maths/check_prime.py)
* [GCD](Maths/gcd.py)
* [Prime Factors](Maths/prime_factors.py)
* [Sieve of eratosthenes](Maths/sieve.py)


# Stack

* [Stack Concept](https://github.com/OmkarPathak/Data-Structures-using-Python/tree/master/Stack/Stack.ipynb)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp