1: write a program to do the following:
a.find the gcd of two numbers using eucid's algorithm .
def gcd(a, b):
if b == 0:
return a
elif b > a:
return gcd(b, a)
else:
return gcd(b, a % b)
B: find the no of integral solution for equation.
#find the no of positive integral for a2-b2=N
from math import sqrt
pf = []
n = int(input("Enter a number: "))
x = n
while n % 2 == 0:
pf.append(2)
n = n // 2
i = 3
while i <= sqrt(n):
while n % i == 0:
pf.append(i)
n = n // i
i = i + 2
if n > 2:
pf.append(n)
print("Prime factors of", x, "are", pf)
pf1 = set(pf)
nf = 1
for f in pf1:
cnt = 0
for f1 in pf:
if f == f1:
cnt += 1
nf *= cnt + 1
print("Number of factors of", x, "=", nf)
print("Number of possible positive integral solutions =", nf // 2)
c: enter a positive number N and find number a and b such that a2-b2=N
N=36
a=9 #factors of 36
b=4
print("the value of positive number N is :",N)
print("factors of N are",a,b)
x=(a+b)/2
y=(a-b)/2
asqr=x**2
bsqr=y**2
print("the value of a**2 and B**2 :",asqr,bsqr)
N=asqr-bsqr
print("asqr-bsqr=",N)
No comments