Skip to content

Commit 012c35f

Browse files
committed
Competitive added
0 parents  commit 012c35f

File tree

1,389 files changed

+102230
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,389 files changed

+102230
-0
lines changed

CP/ Code-Golf/p1.py

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# /*
2+
# *
3+
# ********************************************************************************************
4+
# * AUTHOR : AKASH KANDPAL *
5+
# * Language : Python2 *
6+
# * Motto : The master has failed more times than the beginner has even tried. *
7+
# * IDE used: Atom *
8+
# * My Domain : http://harrypotter.tech/ *
9+
# ********************************************************************************************
10+
# *
11+
# */
12+
from fractions import gcd
13+
import math
14+
import itertools
15+
from itertools import permutations
16+
from itertools import combinations
17+
import calendar
18+
from itertools import product
19+
def readInts():
20+
return list(map(int, raw_input().strip().split()))
21+
def readInt():
22+
return int(raw_input())
23+
def readStrs():
24+
return raw_input().split()
25+
def readStr():
26+
return raw_input().strip()
27+
def readarr(n):
28+
return [map(int,list(readStr())) for i in xrange(n)]
29+
def readnumbertolist():
30+
a=[int(i) for i in list(raw_input())]
31+
return a
32+
def strlistTostr(list1):
33+
return ''.join(list1)
34+
def numlistTostr(list1):
35+
return ''.join(str(e) for e in list1)
36+
def strTolist(str):
37+
return str.split()
38+
def strlistTointlist(str):
39+
return map(int, str)
40+
def slicenum(number,x):
41+
return int(str(number)[:x])
42+
def precise(num):
43+
return "{0:.10f}".format(num)
44+
def rsorted(a):
45+
return sorted(a,reverse=True)
46+
def binar(x):
47+
return '{0:031b}'.format(x)
48+
def findpermute(word):
49+
perms = [''.join(p) for p in permutations(word)]
50+
perms = list(set(perms))
51+
return perms
52+
def findsubsets(S,m):
53+
return list(set(itertools.combinations(S, m)))
54+
def sort1(yy,index):
55+
return yy.sort(key = lambda x:x[index])
56+
def reversepair(yy):
57+
return yy[::-1]
58+
def checkint(x):
59+
return (x).is_integer()
60+
def sum_digits(n):
61+
s = 0
62+
while n:
63+
s += n % 10
64+
n //= 10
65+
return s
66+
def vowel_count(str):
67+
count = 0
68+
vowel = set("aeiouAEIOU")
69+
for alphabet in str:
70+
if alphabet in vowel:
71+
count = count + 1
72+
return count
73+
def leapyear(year):
74+
return calendar.isleap(year)
75+
def factorial(n):
76+
if n == 0:
77+
return 1
78+
else:
79+
return n * factorial(n-1)
80+
def primes_sieve(limit):
81+
limitn = limit+1
82+
not_prime = set()
83+
primes = []
84+
85+
for i in range(2, limitn):
86+
if i in not_prime:
87+
continue
88+
89+
for f in range(i*2, limitn, i):
90+
not_prime.add(f)
91+
92+
primes.append(i)
93+
94+
return primes
95+
def distinctstr(s):
96+
t =''.join(set(s))
97+
return t
98+
def countdict(s):
99+
d ={}
100+
for i in range(len(s)):
101+
if s[i] not in d.keys():
102+
d[s[i]]=1
103+
else:
104+
d[s[i]]+=1
105+
return d
106+
import operator as op
107+
def nck(n, k):
108+
k = min(n-k,k)
109+
result = 1
110+
for i in range(1, k+1):
111+
result = result* (n-i+1) / i
112+
return result
113+
def gcd(a,b):
114+
while b > 0:
115+
a, b = b, a % b
116+
return a
117+
def lcm(a, b):
118+
return a * b / gcd(a, b)
119+
def matrixcheck(x,y):
120+
faadu = []
121+
directions = zip((0,0,1,-1),(1,-1,0,0))
122+
for dx,dy in directions:
123+
if R>x+dx>=0<=y+dy<C and A[x+dx][y+dy]==0:
124+
faadu.append((x+dx,y+dy))
125+
return faadu
126+
def stringcount(s):
127+
return [s.count(i) for i in "abcdefghijklmnopqrstuvwxyz"]
128+
def bubbleSort(arr):
129+
n = len(arr)
130+
for i in range(n):
131+
for j in range(0, n-i-1):
132+
if arr[j] > arr[j+1] :
133+
arr[j], arr[j+1] = arr[j+1], arr[j]
134+
def isSubsetSum(st, n, sm) :
135+
# arr, n, k
136+
subset=[[True] * (sm+1)] * (n+1)
137+
for i in range(0, n+1) :
138+
subset[i][0] = True
139+
for i in range(1, sm + 1) :
140+
subset[0][i] = False
141+
for i in range(1, n+1) :
142+
for j in range(1, sm+1) :
143+
if(j < st[i-1]) :
144+
subset[i][j] = subset[i-1][j]
145+
if (j >= st[i-1]) :
146+
subset[i][j] = subset[i-1][j] or subset[i - 1][j-st[i-1]]
147+
return subset[n][sm];
148+
def decimal_to_octal(dec):
149+
decimal = int(dec)
150+
return oct(decimal)
151+
def decimal_to_binary(dec):
152+
decimal = int(dec)
153+
return bin(decimal)
154+
def decimal_to_hexadecimal(dec):
155+
decimal = int(dec)
156+
return hex(decimal)
157+
def find_duplicate(expr):
158+
stack=[]
159+
char_in_between = 0
160+
f =1
161+
for i in range(0, len(expr)):
162+
if expr[i] == '}' or expr[i] == ')':
163+
pair = '{' if expr[i] == '}' else '('
164+
pop=''
165+
while(len(stack) > 0 and pop != pair):
166+
pop = stack.pop()
167+
if (pop != '{' and pop != '('): char_in_between +=1
168+
if char_in_between == 0:
169+
print "Duplicate"
170+
f =0
171+
break
172+
char_in_between = 0
173+
else:
174+
stack.append(expr[i])
175+
return f
176+
def dictlist(keys,values):
177+
{d.setdefault(key,[]).append(value) for key, value in zip(keys,values)}
178+
return d
179+
def mullistbyconst(my_list,r):
180+
my_new_list = []
181+
for i in my_list:
182+
my_new_list.append(i * r)
183+
return my_new_list
184+
def coinchange(S, m, n):
185+
# (arr,length,sum)
186+
table = [0 for k in range(n+1)]
187+
table[0] = 1
188+
for i in range(0,m):
189+
for j in range(S[i],n+1):
190+
table[j] += table[j-S[i]]
191+
return table[n]
192+
193+
mod = 10 ** 9 + 7
194+
# for i,j in product(xrange(R),xrange(C)):
195+
# print "Case #{}: {}".format(i+1,ans)
196+
p = primes_sieve(100000)
197+
# for __ in range(readInt()):
198+
l,r =readInts()
199+
f = 0
200+
for i in range(l,r+1):
201+
if i in p:
202+
f = 1
203+
break
204+
if f and str(i) == str(i)[::-1]:
205+
print i
206+
else:
207+
print "-1"
208+
'''
209+
100
210+
105
211+
212+
35
213+
87
214+
215+
)101 2)-1
216+
'''

0 commit comments

Comments
 (0)