mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
all valid python 3
This commit is contained in:
parent
b566055e4b
commit
ea2ddaaf6a
@ -99,8 +99,8 @@ def prime_implicant_chart(prime_implicants, binary):
|
|||||||
return chart
|
return chart
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
no_of_variable = int(raw_input("Enter the no. of variables\n"))
|
no_of_variable = int(input("Enter the no. of variables\n"))
|
||||||
minterms = [int(x) for x in raw_input("Enter the decimal representation of Minterms 'Spaces Seprated'\n").split()]
|
minterms = [int(x) for x in input("Enter the decimal representation of Minterms 'Spaces Seprated'\n").split()]
|
||||||
binary = decimal_to_binary(no_of_variable, minterms)
|
binary = decimal_to_binary(no_of_variable, minterms)
|
||||||
|
|
||||||
prime_implicants = check(binary)
|
prime_implicants = check(binary)
|
||||||
@ -113,4 +113,4 @@ def main():
|
|||||||
print(essential_prime_implicants)
|
print(essential_prime_implicants)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -4,9 +4,9 @@ import sys, random, cryptomath_module as cryptoMath
|
|||||||
SYMBOLS = """ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""
|
SYMBOLS = """ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
message = raw_input('Enter message: ')
|
message = input('Enter message: ')
|
||||||
key = int(raw_input('Enter key [2000 - 9000]: '))
|
key = int(input('Enter key [2000 - 9000]: '))
|
||||||
mode = raw_input('Encrypt/Decrypt [E/D]: ')
|
mode = input('Encrypt/Decrypt [E/D]: ')
|
||||||
|
|
||||||
if mode.lower().startswith('e'):
|
if mode.lower().startswith('e'):
|
||||||
mode = 'encrypt'
|
mode = 'encrypt'
|
||||||
|
@ -44,7 +44,7 @@ def decrypt(message):
|
|||||||
print("Decryption using Key #%s: %s" % (key, translated))
|
print("Decryption using Key #%s: %s" % (key, translated))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
message = raw_input("Encrypted message: ")
|
message = input("Encrypted message: ")
|
||||||
message = message.upper()
|
message = message.upper()
|
||||||
decrypt(message)
|
decrypt(message)
|
||||||
|
|
||||||
|
@ -40,25 +40,25 @@ def main():
|
|||||||
print("3.BruteForce")
|
print("3.BruteForce")
|
||||||
print("4.Quit")
|
print("4.Quit")
|
||||||
while True:
|
while True:
|
||||||
choice = raw_input("What would you like to do?: ")
|
choice = input("What would you like to do?: ")
|
||||||
if choice not in ['1', '2', '3', '4']:
|
if choice not in ['1', '2', '3', '4']:
|
||||||
print ("Invalid choice")
|
print ("Invalid choice")
|
||||||
elif choice == '1':
|
elif choice == '1':
|
||||||
strng = raw_input("Please enter the string to be ecrypted: ")
|
strng = input("Please enter the string to be ecrypted: ")
|
||||||
while True:
|
while True:
|
||||||
key = int(input("Please enter off-set between 1-94: "))
|
key = int(input("Please enter off-set between 1-94: "))
|
||||||
if key in range(1, 95):
|
if key in range(1, 95):
|
||||||
print (encrypt(strng, key))
|
print (encrypt(strng, key))
|
||||||
main()
|
main()
|
||||||
elif choice == '2':
|
elif choice == '2':
|
||||||
strng = raw_input("Please enter the string to be decrypted: ")
|
strng = input("Please enter the string to be decrypted: ")
|
||||||
while True:
|
while True:
|
||||||
key = raw_int(input("Please enter off-set between 1-94: "))
|
key = raw_int(input("Please enter off-set between 1-94: "))
|
||||||
if key > 0 and key <= 94:
|
if key > 0 and key <= 94:
|
||||||
print(decrypt(strng, key))
|
print(decrypt(strng, key))
|
||||||
main()
|
main()
|
||||||
elif choice == '3':
|
elif choice == '3':
|
||||||
strng = raw_input("Please enter the string to be decrypted: ")
|
strng = input("Please enter the string to be decrypted: ")
|
||||||
brute_force(strng)
|
brute_force(strng)
|
||||||
main()
|
main()
|
||||||
elif choice == '4':
|
elif choice == '4':
|
||||||
|
@ -6,7 +6,7 @@ BYTE_SIZE = 256
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
filename = 'encrypted_file.txt'
|
filename = 'encrypted_file.txt'
|
||||||
response = raw_input('Encrypte\Decrypt [e\d]: ')
|
response = input('Encrypte\Decrypt [e\d]: ')
|
||||||
|
|
||||||
if response.lower().startswith('e'):
|
if response.lower().startswith('e'):
|
||||||
mode = 'encrypt'
|
mode = 'encrypt'
|
||||||
|
@ -4,9 +4,9 @@ import sys, random
|
|||||||
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
message = raw_input('Enter message: ')
|
message = input('Enter message: ')
|
||||||
key = 'LFWOAYUISVKMNXPBDCRJTQEGHZ'
|
key = 'LFWOAYUISVKMNXPBDCRJTQEGHZ'
|
||||||
resp = raw_input('Encrypt/Decrypt [e/d]: ')
|
resp = input('Encrypt/Decrypt [e/d]: ')
|
||||||
|
|
||||||
checkValidKey(key)
|
checkValidKey(key)
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ from __future__ import print_function
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
message = raw_input('Enter message: ')
|
message = input('Enter message: ')
|
||||||
key = int(raw_input('Enter key [2-%s]: ' % (len(message) - 1)))
|
key = int(input('Enter key [2-%s]: ' % (len(message) - 1)))
|
||||||
mode = raw_input('Encryption/Decryption [e/d]: ')
|
mode = input('Encryption/Decryption [e/d]: ')
|
||||||
|
|
||||||
if mode.lower().startswith('e'):
|
if mode.lower().startswith('e'):
|
||||||
text = encryptMessage(key, message)
|
text = encryptMessage(key, message)
|
||||||
|
@ -5,15 +5,15 @@ import transposition_cipher as transCipher
|
|||||||
def main():
|
def main():
|
||||||
inputFile = 'Prehistoric Men.txt'
|
inputFile = 'Prehistoric Men.txt'
|
||||||
outputFile = 'Output.txt'
|
outputFile = 'Output.txt'
|
||||||
key = int(raw_input('Enter key: '))
|
key = int(input('Enter key: '))
|
||||||
mode = raw_input('Encrypt/Decrypt [e/d]: ')
|
mode = input('Encrypt/Decrypt [e/d]: ')
|
||||||
|
|
||||||
if not os.path.exists(inputFile):
|
if not os.path.exists(inputFile):
|
||||||
print('File %s does not exist. Quitting...' % inputFile)
|
print('File %s does not exist. Quitting...' % inputFile)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if os.path.exists(outputFile):
|
if os.path.exists(outputFile):
|
||||||
print('Overwrite %s? [y/n]' % outputFile)
|
print('Overwrite %s? [y/n]' % outputFile)
|
||||||
response = raw_input('> ')
|
response = input('> ')
|
||||||
if not response.lower().startswith('y'):
|
if not response.lower().startswith('y'):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@ from __future__ import print_function
|
|||||||
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
message = raw_input('Enter message: ')
|
message = input('Enter message: ')
|
||||||
key = raw_input('Enter key [alphanumeric]: ')
|
key = input('Enter key [alphanumeric]: ')
|
||||||
mode = raw_input('Encrypt/Decrypt [e/d]: ')
|
mode = input('Encrypt/Decrypt [e/d]: ')
|
||||||
|
|
||||||
if mode.lower().startswith('e'):
|
if mode.lower().startswith('e'):
|
||||||
mode = 'encrypt'
|
mode = 'encrypt'
|
||||||
|
@ -35,8 +35,8 @@ def BellmanFord(graph, V, E, src):
|
|||||||
|
|
||||||
|
|
||||||
#MAIN
|
#MAIN
|
||||||
V = int(raw_input("Enter number of vertices: "))
|
V = int(input("Enter number of vertices: "))
|
||||||
E = int(raw_input("Enter number of edges: "))
|
E = int(input("Enter number of edges: "))
|
||||||
|
|
||||||
graph = [dict() for j in range(E)]
|
graph = [dict() for j in range(E)]
|
||||||
|
|
||||||
@ -45,10 +45,10 @@ for i in range(V):
|
|||||||
|
|
||||||
for i in range(E):
|
for i in range(E):
|
||||||
print("\nEdge ",i+1)
|
print("\nEdge ",i+1)
|
||||||
src = int(raw_input("Enter source:"))
|
src = int(input("Enter source:"))
|
||||||
dst = int(raw_input("Enter destination:"))
|
dst = int(input("Enter destination:"))
|
||||||
weight = float(raw_input("Enter weight:"))
|
weight = float(input("Enter weight:"))
|
||||||
graph[i] = {"src": src,"dst": dst, "weight": weight}
|
graph[i] = {"src": src,"dst": dst, "weight": weight}
|
||||||
|
|
||||||
gsrc = int(raw_input("\nEnter shortest path source:"))
|
gsrc = int(input("\nEnter shortest path source:"))
|
||||||
BellmanFord(graph, V, E, gsrc)
|
BellmanFord(graph, V, E, gsrc)
|
||||||
|
@ -38,8 +38,8 @@ def Dijkstra(graph, V, src):
|
|||||||
|
|
||||||
|
|
||||||
#MAIN
|
#MAIN
|
||||||
V = int(raw_input("Enter number of vertices: "))
|
V = int(input("Enter number of vertices: "))
|
||||||
E = int(raw_input("Enter number of edges: "))
|
E = int(input("Enter number of edges: "))
|
||||||
|
|
||||||
graph = [[float('inf') for i in range(V)] for j in range(V)]
|
graph = [[float('inf') for i in range(V)] for j in range(V)]
|
||||||
|
|
||||||
@ -48,10 +48,10 @@ for i in range(V):
|
|||||||
|
|
||||||
for i in range(E):
|
for i in range(E):
|
||||||
print("\nEdge ",i+1)
|
print("\nEdge ",i+1)
|
||||||
src = int(raw_input("Enter source:"))
|
src = int(input("Enter source:"))
|
||||||
dst = int(raw_input("Enter destination:"))
|
dst = int(input("Enter destination:"))
|
||||||
weight = float(raw_input("Enter weight:"))
|
weight = float(input("Enter weight:"))
|
||||||
graph[src][dst] = weight
|
graph[src][dst] = weight
|
||||||
|
|
||||||
gsrc = int(raw_input("\nEnter shortest path source:"))
|
gsrc = int(input("\nEnter shortest path source:"))
|
||||||
Dijkstra(graph, V, gsrc)
|
Dijkstra(graph, V, gsrc)
|
||||||
|
@ -30,8 +30,8 @@ def FloydWarshall(graph, V):
|
|||||||
|
|
||||||
|
|
||||||
#MAIN
|
#MAIN
|
||||||
V = int(raw_input("Enter number of vertices: "))
|
V = int(input("Enter number of vertices: "))
|
||||||
E = int(raw_input("Enter number of edges: "))
|
E = int(input("Enter number of edges: "))
|
||||||
|
|
||||||
graph = [[float('inf') for i in range(V)] for j in range(V)]
|
graph = [[float('inf') for i in range(V)] for j in range(V)]
|
||||||
|
|
||||||
@ -40,9 +40,9 @@ for i in range(V):
|
|||||||
|
|
||||||
for i in range(E):
|
for i in range(E):
|
||||||
print("\nEdge ",i+1)
|
print("\nEdge ",i+1)
|
||||||
src = int(raw_input("Enter source:"))
|
src = int(input("Enter source:"))
|
||||||
dst = int(raw_input("Enter destination:"))
|
dst = int(input("Enter destination:"))
|
||||||
weight = float(raw_input("Enter weight:"))
|
weight = float(input("Enter weight:"))
|
||||||
graph[src][dst] = weight
|
graph[src][dst] = weight
|
||||||
|
|
||||||
FloydWarshall(graph, V)
|
FloydWarshall(graph, V)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
num_nodes, num_edges = list(map(int,raw_input().split()))
|
num_nodes, num_edges = list(map(int,input().split()))
|
||||||
|
|
||||||
edges = []
|
edges = []
|
||||||
|
|
||||||
for i in range(num_edges):
|
for i in range(num_edges):
|
||||||
node1, node2, cost = list(map(int,raw_input().split()))
|
node1, node2, cost = list(map(int,input().split()))
|
||||||
edges.append((i,node1,node2,cost))
|
edges.append((i,node1,node2,cost))
|
||||||
|
|
||||||
edges = sorted(edges, key=lambda edge: edge[3])
|
edges = sorted(edges, key=lambda edge: edge[3])
|
||||||
|
@ -101,8 +101,8 @@ def PrimsAlgorithm(l):
|
|||||||
return TreeEdges
|
return TreeEdges
|
||||||
|
|
||||||
# < --------- Prims Algorithm --------- >
|
# < --------- Prims Algorithm --------- >
|
||||||
n = int(raw_input("Enter number of vertices: "))
|
n = int(input("Enter number of vertices: "))
|
||||||
e = int(raw_input("Enter number of edges: "))
|
e = int(input("Enter number of edges: "))
|
||||||
adjlist = defaultdict(list)
|
adjlist = defaultdict(list)
|
||||||
for x in range(e):
|
for x in range(e):
|
||||||
l = [int(x) for x in input().split()]
|
l = [int(x) for x in input().split()]
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
# n - no of nodes, m - no of edges
|
# n - no of nodes, m - no of edges
|
||||||
n, m = list(map(int,raw_input().split()))
|
n, m = list(map(int,input().split()))
|
||||||
|
|
||||||
g = [[] for i in range(n)] #graph
|
g = [[] for i in range(n)] #graph
|
||||||
r = [[] for i in range(n)] #reversed graph
|
r = [[] for i in range(n)] #reversed graph
|
||||||
# input graph data (edges)
|
# input graph data (edges)
|
||||||
for i in range(m):
|
for i in range(m):
|
||||||
u, v = list(map(int,raw_input().split()))
|
u, v = list(map(int,input().split()))
|
||||||
g[u].append(v)
|
g[u].append(v)
|
||||||
r[v].append(u)
|
r[v].append(u)
|
||||||
|
|
||||||
|
@ -120,5 +120,5 @@ network.trannig()
|
|||||||
while True:
|
while True:
|
||||||
sample = []
|
sample = []
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
sample.insert(i, float(raw_input('value: ')))
|
sample.insert(i, float(input('value: ')))
|
||||||
network.sort(sample)
|
network.sort(sample)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import math
|
import math
|
||||||
n = int(raw_input("Enter n: "))
|
n = int(input("Enter n: "))
|
||||||
|
|
||||||
def sieve(n):
|
def sieve(n):
|
||||||
l = [True] * (n+1)
|
l = [True] * (n+1)
|
||||||
@ -21,4 +21,4 @@ def sieve(n):
|
|||||||
return prime
|
return prime
|
||||||
|
|
||||||
print(sieve(n))
|
print(sieve(n))
|
||||||
|
|
||||||
|
@ -120,5 +120,5 @@ network.trannig()
|
|||||||
while True:
|
while True:
|
||||||
sample = []
|
sample = []
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
sample.insert(i, float(raw_input('value: ')))
|
sample.insert(i, float(input('value: ')))
|
||||||
network.sort(sample)
|
network.sort(sample)
|
||||||
|
@ -37,7 +37,7 @@ def is_balanced(S):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
S = raw_input("Enter sequence of brackets: ")
|
S = input("Enter sequence of brackets: ")
|
||||||
|
|
||||||
if is_balanced(S):
|
if is_balanced(S):
|
||||||
print((S, "is balanced"))
|
print((S, "is balanced"))
|
||||||
|
@ -19,7 +19,7 @@ def moveDisk(fp,tp):
|
|||||||
print(('moving disk from', fp, 'to', tp))
|
print(('moving disk from', fp, 'to', tp))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
height = int(raw_input('Height of hanoi: '))
|
height = int(input('Height of hanoi: '))
|
||||||
moveTower(height, 'A', 'B', 'C')
|
moveTower(height, 'A', 'B', 'C')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -7,7 +7,7 @@ By considering the terms in the Fibonacci sequence whose values do not exceed n,
|
|||||||
e.g. for n=10, we have {2,8}, sum is 10.
|
e.g. for n=10, we have {2,8}, sum is 10.
|
||||||
'''
|
'''
|
||||||
"""Python 3"""
|
"""Python 3"""
|
||||||
n = int(raw_input())
|
n = int(input())
|
||||||
a=0
|
a=0
|
||||||
b=2
|
b=2
|
||||||
count=0
|
count=0
|
||||||
|
@ -19,7 +19,7 @@ def isprime(no):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
maxNumber = 0
|
maxNumber = 0
|
||||||
n=int(raw_input())
|
n=int(input())
|
||||||
if(isprime(n)):
|
if(isprime(n)):
|
||||||
print(n)
|
print(n)
|
||||||
else:
|
else:
|
||||||
|
@ -4,7 +4,7 @@ The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor o
|
|||||||
e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
|
e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
|
||||||
'''
|
'''
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
n=int(raw_input())
|
n=int(input())
|
||||||
prime=1
|
prime=1
|
||||||
i=2
|
i=2
|
||||||
while(i*i<=n):
|
while(i*i<=n):
|
||||||
|
@ -4,7 +4,7 @@ A palindromic number reads the same both ways. The largest palindrome made from
|
|||||||
Find the largest palindrome made from the product of two 3-digit numbers which is less than N.
|
Find the largest palindrome made from the product of two 3-digit numbers which is less than N.
|
||||||
'''
|
'''
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
limit = int(raw_input("limit? "))
|
limit = int(input("limit? "))
|
||||||
|
|
||||||
# fetchs the next number
|
# fetchs the next number
|
||||||
for number in range(limit-1,10000,-1):
|
for number in range(limit-1,10000,-1):
|
||||||
@ -26,4 +26,4 @@ for number in range(limit-1,10000,-1):
|
|||||||
print(number)
|
print(number)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
divisor -=1
|
divisor -=1
|
||||||
|
@ -12,8 +12,8 @@ for i in range(999,100,-1):
|
|||||||
arr.append(i*j)
|
arr.append(i*j)
|
||||||
arr.sort()
|
arr.sort()
|
||||||
|
|
||||||
n=int(raw_input())
|
n=int(input())
|
||||||
for i in arr[::-1]:
|
for i in arr[::-1]:
|
||||||
if(i<n):
|
if(i<n):
|
||||||
print(i)
|
print(i)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
@ -5,7 +5,7 @@ What is the smallest positive number that is evenly divisible(divisible with no
|
|||||||
'''
|
'''
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
n = int(raw_input())
|
n = int(input())
|
||||||
i = 0
|
i = 0
|
||||||
while 1:
|
while 1:
|
||||||
i+=n*(n-1)
|
i+=n*(n-1)
|
||||||
@ -18,4 +18,4 @@ while 1:
|
|||||||
if(i==0):
|
if(i==0):
|
||||||
i=1
|
i=1
|
||||||
print(i)
|
print(i)
|
||||||
break
|
break
|
||||||
|
@ -13,7 +13,7 @@ def gcd(x,y):
|
|||||||
def lcm(x,y):
|
def lcm(x,y):
|
||||||
return (x*y)//gcd(x,y)
|
return (x*y)//gcd(x,y)
|
||||||
|
|
||||||
n = int(raw_input())
|
n = int(input())
|
||||||
g=1
|
g=1
|
||||||
for i in range(1,n+1):
|
for i in range(1,n+1):
|
||||||
g=lcm(g,i)
|
g=lcm(g,i)
|
||||||
|
@ -12,9 +12,9 @@ from __future__ import print_function
|
|||||||
|
|
||||||
suma = 0
|
suma = 0
|
||||||
sumb = 0
|
sumb = 0
|
||||||
n = int(raw_input())
|
n = int(input())
|
||||||
for i in range(1,n+1):
|
for i in range(1,n+1):
|
||||||
suma += i**2
|
suma += i**2
|
||||||
sumb += i
|
sumb += i
|
||||||
sum = sumb**2 - suma
|
sum = sumb**2 - suma
|
||||||
print(sum)
|
print(sum)
|
||||||
|
@ -9,8 +9,8 @@ Hence the difference between the sum of the squares of the first ten natural num
|
|||||||
Find the difference between the sum of the squares of the first N natural numbers and the square of the sum.
|
Find the difference between the sum of the squares of the first N natural numbers and the square of the sum.
|
||||||
'''
|
'''
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
n = int(raw_input())
|
n = int(input())
|
||||||
suma = n*(n+1)/2
|
suma = n*(n+1)/2
|
||||||
suma **= 2
|
suma **= 2
|
||||||
sumb = n*(n+1)*(2*n+1)/6
|
sumb = n*(n+1)*(2*n+1)/6
|
||||||
print(suma-sumb)
|
print(suma-sumb)
|
||||||
|
@ -16,7 +16,7 @@ def isprime(n):
|
|||||||
if(n%i==0):
|
if(n%i==0):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
n = int(raw_input())
|
n = int(input())
|
||||||
i=0
|
i=0
|
||||||
j=1
|
j=1
|
||||||
while(i!=n and j<3):
|
while(i!=n and j<3):
|
||||||
@ -27,4 +27,4 @@ while(i!=n):
|
|||||||
j+=2
|
j+=2
|
||||||
if(isprime(j)):
|
if(isprime(j)):
|
||||||
i+=1
|
i+=1
|
||||||
print(j)
|
print(j)
|
||||||
|
@ -4,7 +4,7 @@ def isprime(number):
|
|||||||
if number%i==0:
|
if number%i==0:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
n = int(raw_input('Enter The N\'th Prime Number You Want To Get: ')) # Ask For The N'th Prime Number Wanted
|
n = int(input('Enter The N\'th Prime Number You Want To Get: ')) # Ask For The N'th Prime Number Wanted
|
||||||
primes = []
|
primes = []
|
||||||
num = 2
|
num = 2
|
||||||
while len(primes) < n:
|
while len(primes) < n:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
def main():
|
def main():
|
||||||
LargestProduct = -sys.maxsize-1
|
LargestProduct = -sys.maxsize-1
|
||||||
number=raw_input().strip()
|
number=input().strip()
|
||||||
for i in range(len(number)-13):
|
for i in range(len(number)-13):
|
||||||
product=1
|
product=1
|
||||||
for j in range(13):
|
for j in range(13):
|
||||||
|
@ -6,7 +6,7 @@ Find maximum possible value of product of a,b,c among all such Pythagorean tripl
|
|||||||
|
|
||||||
product=-1
|
product=-1
|
||||||
d=0
|
d=0
|
||||||
N = int(raw_input())
|
N = int(input())
|
||||||
for a in range(1,N//3):
|
for a in range(1,N//3):
|
||||||
"""Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c """
|
"""Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c """
|
||||||
b=(N*N-2*a*N)//(2*N-2*a)
|
b=(N*N-2*a*N)//(2*N-2*a)
|
||||||
|
@ -4,11 +4,11 @@ Work out the first ten digits of the sum of the N 50-digit numbers.
|
|||||||
'''
|
'''
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
n = int(raw_input().strip())
|
n = int(input().strip())
|
||||||
|
|
||||||
array = []
|
array = []
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
array.append(int(raw_input().strip()))
|
array.append(int(input().strip()))
|
||||||
|
|
||||||
print(str(sum(array))[:10])
|
print(str(sum(array))[:10])
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
power = int(raw_input("Enter the power of 2: "))
|
power = int(input("Enter the power of 2: "))
|
||||||
num = 2**power
|
num = 2**power
|
||||||
|
|
||||||
string_num = str(num)
|
string_num = str(num)
|
||||||
|
@ -15,7 +15,7 @@ def split_and_add(number):
|
|||||||
return sum_of_digits
|
return sum_of_digits
|
||||||
|
|
||||||
# Taking the user input.
|
# Taking the user input.
|
||||||
number = int(raw_input("Enter the Number: "))
|
number = int(input("Enter the Number: "))
|
||||||
|
|
||||||
# Assigning the factorial from the factorial function.
|
# Assigning the factorial from the factorial function.
|
||||||
factorial = factorial(number)
|
factorial = factorial(number)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user