AREA OF CIRCLE
a=int(input())
print(format(3.14*a*a,'.2f'))
CELSIUS TO FAHRENHEIT
a=int(input())
print(format(a*9/5+32,'.2f'))
FAHRENHEIT TO CELSIUS
a=int(input())
print(format((a-32)*5/9,'.2f'))
COMPOUND INTEREST
p,r,t=map(int,input().split())
a=p*((1+r/100)**t)
print(format(a,'.2f'))
SIMPLE INTEREST
p,t,r=map(int,input().split())
print(p*t*r//100)
PRIMES IN RANGE
def prime(n):
for i in range(2,int(n**0.5)+1):
if(n%i==0):
return 0
else:
if(n!=0 and n!=1):
return 1
m=int(input())
n=int(input())
c=0
for i in range(m,n+1):
if(prime(i)):
c+=1
print(c)
DIAGONALS OF POLYGON
n=int(input())
print(n*(n-3)//2)
LCM_of_n_numbers
def lcm(a,b):
maxi=max(a,b)
while True:
if maxi%a==0 and maxi%b==0:
break
else:
maxi+=max(a,b)
return maxi
n=int(input())
a=list(map(int,input().split()))
l=lcm(a[0],a[1])
for i in range(2,n):
l=lcm(l,a[i])
print(l)
octal_to_binary
n=int(input())
i=0
sum=0
while(n!=0):
s=n%10
sum=sum+(s)*(8**i)
n=n//10
i+=1
print ("{0:b}".format(sum))
ANGLE BETWEEN HANDS
h,m=map(int,input().split(':'))
angle=abs(30*h-(11/2)*m)
if angle>180:
print(360-angle)
else:
print(angle)
Flip_and_Win
n=int(input())
s=input()
a=0
i=0
while i<n-1:
a+=abs(int(s[i+1])-int(s[i]))
i+=1
a=n-a-1
if(a%3==0):
print('Sudhir')
else:
print('Ashok')
Evaluate_the_Expression(Calculator)
import math
s=str(input())
print(eval(s))
Make_XOR_Zero
def xored(arr, data, add, n):
res = 0
for i in arr:
res ^= ((i + data) & add)
return res;
def solve(arr, n):
add = 1
res = 0
maxim = max(arr)
while add <= maxim:
xr = xored(arr, res, add, n)
if xr != 0:
res += add
add += 1
xr = 0
for i in arr:
xr ^= (i + res)
if xr == 0:
return res
return -1
n = int(input())
arr = list(map(int, input().split()))
print(solve(arr, n))
Can_Robber_Escape
n=int(input())
c=0
a=list(map(int,input().split()))
for i in range(len(a)):
if(a[i]%2!=0):
c+=1
if(c<=2):
print('YES')
else:
print('NO')
Total_Money
n=int(input())
for j in range(n):
a,b,c,d=map(int,input().split())
x=a//b
y=a%b
s=0
for i in range(x):
s+=(c+i*d)*b
s+=(c+x*d)*y
print(s)
Count_of_the_non-prime_divisors_of_a_given_number
n=int(input())
c=0
co=0
for i in range(1,n+1):
if(n%i==0):
for j in range(1,i+1):
if(i%j==0):
c+=1
if(c!=2):
co+=1
c=0
print(co)
PROGRAM TO PRINT ALL PALINDROMES IN GIVEN RANGE
a=int(input())
b=int(input())
for i in range(a,b+1):
a=str(i)
if a==a[::-1]:
print(a,end=' ')
EVEN ODD MIXED
a=input()
even=0
for i in a:
if int(i)%2==0:
even+=1
if(even==len(a)):
print('Even')
elif(even==0):
print('Odd')
else:
print('Mixed')
GRADES OF RIDE
h,s,sp=map(int,input().split())
a,b,c=h>50,s>60,sp>100
if(a==True and b==True and c==True):
print(10)
elif(a==True and b ==True):
print(9)
elif(b==True and c==True):
print(8)
elif(a==True and c ==True):
print(7)
elif(a==False and b==False and c==False):
print(5)
else:
print(6)
ROY AND PROFILE PICTURE
l=int(input())
n=int(input())
for i in range(n):
w,h=map(int,input().split())
if w<l or h<l:
print('UPLOAD ANOTHER')
elif w==h:
print('ACCEPTED')
else:
print('CROP IT')
COUNT DIVISERS
l,r,k=map(int,input().split())
count=0
for i in range(l,r+1):
if i%k==0:
count+=1
print(count)
SMALL FACTORIALS
t=int(input())
for i in range(t):
a=int(input())
p=1
for i in range(2,a+1):
p*=i
print(p)
Battle of Primes
def prime(n):
for i in range(2,int(n**0.5)+1):
if(n%i==0):
return 0
else:
return 1
m=int(input())
n=int(input())
t=m+n
i=1
while(1):
q=t+i
if(prime(q)):
print(i)
break
i+=1
POWER OF A NUMBER
x,y,m=map(int,input().split())
print(x**y%m)
Permutation_Sequence
from itertools import permutations
a,b=map(int,input().split())
l=list(permutations(range(1,a+1)))
for i in l[b-1]:
print(i,end='')
Play_with_Fibonacci_sequence
def fibo(n):
a,b=0,1
i=2
print(a,b,end=' ')
while i<n:
c=a+b
print(c,end=' ')
a=b
b=c
i+=1
n=int(input())
fibo(n)
Generate_Prime_Numbers_In_A_Interval
m=int(input())
n=int(input())
for a in range(m,n+1):
for i in range(2,int(a**0.5)+1):
if(a%i==0):
break
else:
if(a!=1):
print(a)
Add_Digits
n=int(input())
sum=0
while(sum==0 or sum>9):
sum=0
while(n>0):
d=n%10
sum=sum+d
n=n//10
n=sum;
print(n)
VALID PERFECT SQUARE
t=int(input())
for i in range(t):
a=int(input())
b=a**0.5
print(b==int(b))
Perfect_Number
n=int(input())
sum=0
for i in range(1,(n//2)+1):
if(n%i==0):
sum=sum+i
if(sum==n):
print('True')
else:
print('False')
Self_Dividing_Numbers
def dividing(n):
c=0
temp=n
l=len(str(n))
while(n!=0):
d=n%10
if(d!=0):
if(temp%d==0):
c+=1
n=n//10
if(c==l):
return temp
m=int(input())
n=int(input())
for i in range(m,n+1):
if(dividing(i)):
print(i,end=' ')
SUBRACT THE PRODUCT AND SUM OF DIGITS OF AN NUMBER
a=input()
s,p=0,1
for i in a:
p*=int(i)
s+=int(i)
print(p-s)
Maximum_69_Number
def maximum69Number (self, num: int) -> int:
return(str(num).replace('6', '9', 1))
n=input()
print( maximum69Number(1,n))
STRONG NUMBER
def fact(d):
i=1
f=1
while(i<=d):
f=f*i
i=i+1
return f
n=int(input())
sum=0
temp=n
while(n):
d=n%10
sum=sum+fact(d)
n=n//10
if(sum==temp):
print("The number",temp,"is a strong number")
else:
print("The number",temp,"is not a strong number")
SPY NUMBER
a=input()
s,p=0,1
for i in a:
s+=int(i)
p*=int(i)
if(s==p):
print('Spy Number')
else:
print('Not Spy Number')
NEON NUMBER
a=int(input())
b=str(a*a)
sum=0
for i in b:
sum+=int(i)
if(sum==a):
print("Neon Number")
else:
print('Not Neon Number')
Nearest_Prime
def prime(n):
if n==1:
return 0
for i in range(2,int(n**0.5)+1):
if n%i==0:
return 0
return 1
x=int(input())
for j in range(x):
n=int(input())
temp=n
for i in range(n,2-1,-1):
if prime(i):
p=i
break
while temp!=0:
if prime(temp):
q=temp
break
temp+=1
if (n-p)<=(q-n):
print(p)
else:
print(q)
nearest_fibonacci
def fib(n):
a=0
b=1
c=a+b
while c<n:
c=a+b
a=b
b=c
if c==n:
return 1
return 0
n=int(input())
temp=n
for i in range(n,0,-1):
if fib(i):
p=i
break
while temp!=0:
if fib(temp):
q=temp
break
temp+=1
if (n-p)<(q-n):
print(p)
elif (n-p)==(q-n):
print(p,q)
else:
print(q)
Monk_and_Square_Root.
n=int(input())
k=-1
while(n):
k=-1
a,b=map(int,input().split())
for i in range(0,b+1):
if((i*i)%b==a):
k=i
break
print(k)
n=n-1
Minimum_absolute_difference_of_a_number_and_its_closest_prime
def prime(n):
if n==1:
return 0
for i in range(2,int(n**0.5)+1):
if n%i==0:
return 0
return 1
n=int(input())
temp=n
for i in range(n,1,-1):
if prime(i):
p=i
break
while temp!=0:
if prime(temp):
q=temp
break
temp=temp+1
if (n-p)<(q-n):
print(abs(n-p))
elif (n-p)==(q-n):
print(abs(n-p))
else:
print(abs(n-q))
Minimum_absolute_difference_between_N_and_a_power_of_2
from math import floor, log2
def minAbs(n) :
l=pow(2,floor(log2(n)))
r=l*2
return min((n-l),(r-n))
if __name__ == "__main__" :
n=int(input())
print(minAbs(n))
mega_prime
n=int(input())
c=0
dc=0
for i in range(2,int(n**0.5)+1):
if(n%i==0):
print('Not Mega Prime')
break
else:
while(n):
d=n%10
n=n//10
c+=1
if(d==2 or d==3 or d==5 or d==7):
dc+=1
if(dc==c):
print('Mega Prime')
else:
print('Not Mega Prime')
LCM
a,b=map(int,input().split())
for i in range(1,a+1 and b+1):
if(a%i==0 and b%i==0):
gcd=i
lcm=(a*b)//gcd
print(lcm)
Roman_to_Integer
def value(r):
if (r=='I'):
return 1
if (r=='V'):
return 5
if (r=='X'):
return 10
if (r=='L'):
return 50
if (r=='C'):
return 100
if (r=='D'):
return 500
if (r=='M'):
return 1000
return -1
def roman(str):
res=0
i=0
while(i<len(str)):
s1=value(str[i])
if (i+1<len(str)):
s2=value(str[i+1])
if (s1>=s2):
res=res+s1
i=i+1
else:
res=res+s2-s1
i=i+2
else:
res=res+s1
i=i+1
return res
n=input()
print(roman(n))
PALINDROME NUMBER
t=int(input())
for i in range(t):
a=input()
print(a==a[::-1])
REVERSE INTEGER
a=input()
if '-' in a:
print(int('-'+a[:0:-1]))
else:
print(int(a[::-1]))
PRONIC NUMBER OR HETEROMECIC NUMBER
a=int(input())
for i in range(int(a**0.5),a):
if(i*(i+1))==a:
print('YES')
break
else:
print('NO')
circular_prime
def prime(n):
for i in range(2,int(n**0.5)+1):
if(n%i==0):
break
else:
return 1
n=int(input())
if(prime(n)):
sum=0
while(n!=0):
d=n%10
sum=sum*10+d
n=n//10
if(prime(sum)):
print('circular prime')
else:
print('prime but not a circular prime')
else:
print('not prime')
AUTOMORPHIC NUMBER
a=int(input())
a=str(abs(a))
l=len(a)
b=str(int(a)**2)
if a==b[-l:]:
print('Automorphic Number')
else:
print('Not an Automorphic Number')
AMICABLE NUMBERS
def ami(a):
sum=0
for i in range(1,a):
if(a%i==0):
sum+=i
return sum
n1=int(input())
n2=int(input())
n3=ami(n1)
n4=ami(n2)
if(n1==n4 and n2==n3):
print('Amicable')
else:
print('Not Amicable')
UNIQUE NUMBER
a=input()
n=set(a)
if(len(a)==len(n)):
print("Unique Number")
else:
print("Not Unique Number")
SUM OF THE GIVEN NUMBERS
t=int(input())
for i in range(t):
a,b=map(int,input().split())
print(a+b)
PHONE_NUMBER_VALIDATION
n=int(input())
i=0
c=0
while n!=0:
c+=1
n=n//10
if c==10:
print('Valid')
else:
print('Invalid')
Ugly_number
n=int(input())
c=0
while(n!=1):
if(n%2==0):
n=n//2
elif(n%3==0):
n=n//3
elif(n%5==0):
n=n//5
else:
print('Not Ugly Number')
c+=1
break
if(c==0):
print('Ugly Number')
prime_number
n=int(input())
c=0
for i in range(2,int(n**0.5)+1):
if(n%i==0):
c+=1
if(c==0):
print('prime')
else:
print('not a prime')
PERFECT SQUARE ROOT OR NOT
a=int(input())
for i in range(1,a):
if(a==i*i):
break
print(a==i*i)
REVERSE OF A NUMBERS
a=input()
print(a[::-1])
LARGEST DIGIT
a=input()
l=[]
for i in a:
l.append(i)
print(max(l))
happy_number
n=int(input())
sum=0
while(sum!=1 and sum!=4):
sum=0
while(n!=0):
d=n%10
sum=sum+(d*d)
n=n//10
n=sum
if(sum==1):
print("True")
else:
print("False")
ADAM NUMBER
n=input()
a=int(n)**2
b=int(n[::-1])**2
b=str(b)
if(str(a)==b[::-1]):
print('True')
else:
print('False')
GCD OR HCF
def gcd(a,b):
r=min(a,b)
while r:
if a%r==0 and b%r==0:
break
r-=1
return r
a,b=map(int,input().split())
print(gcd(a,b))
Find_two_distinct_prime_numbers_with_given_product
def prime(n):
for i in range(2,int(n**0.5)+1):
if(n%i==0):
return 0
else:
return 1
n=int(input())
c=0
for i in range(2,n+1):
for j in range(2,n+1):
if(prime(i) and prime(j) and i*j==n and i<j):
print(i,j)
c+=1
if(c==0):
print('-1')
FIBONACCI OR NOT
n=int(input())
a,b=0,1,
for i in range(n):
if(a==n):
break
a,b=b,a+b
print(a==n)
FIBONACCI
n=int(input())
a,b,=0,1
for i in range(n):
print(a,end=' ')
a,b=b,a+b
DISARIUM NUMBER
n=input()
j,sum=1,0
for i in n:
sum+=int(i)**j
j+=1
print(sum==int(n))
ABUNDANT_NUMBERS
n=int(input())
sum=0
for i in range(1,n//2+1):
if(n%i==0):
sum+=i
print(sum>n)
Closest_Palindrome
def is_palin(j):
m = j
s=0
while m!=0:
v = m%10
s = s*10+v
m = m//10
if j==s:
return j
x = int(input())
for i in range(x-1,1,-1):
if is_palin(i):
a = i
break
g = x+1
while g!=0:
if is_palin(g):
b = g
break
g+=1
if (x-a)<(b-x):
print(a)
elif (x-a)==(b-x):
print(a,b)
else:
print(b)
PALINDROME
n=input()
a=n[::-1]
if(n==a):
print('True')
else:
print('False')
ABSOLUTE DIFFERENCE NUMBERS
N,X=map(int,input().split())
N=str(N)
a=int(N[0:X])
b=int(N[-X:])
print(abs(a-b))
TABLES
a,b=map(int,input().split())
for i in range(1,b+1,2):
if i%2!=0 :
print(a,'x',i,'=',i*a)
Count_number_of_ways_to_cover_a_distance
def fun(n):
if n<0:
return 0
if n==0:
return 1
return fun(n-1)+fun(n-2)+fun(n-3)
a=int(input())
print(fun(a))