Skip to content

Commit

Permalink
Hackon Feb
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypotter0 committed Feb 24, 2018
1 parent cb9f0dd commit 43e62d7
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 28 deletions.
Empty file added CP/ C Cubed/prob1.py
Empty file.
12 changes: 12 additions & 0 deletions CP/Hackon Feb/prob1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def readInts():
return list(map(int, input().split()))
def readInt():
return int(input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))

t=input()
for __ in range(t):
n = readInt()
a = n//7
print(7*(a*(a+1)//2))
37 changes: 37 additions & 0 deletions CP/Hackon Feb/prob2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def readInts():
return list(map(int, raw_input().split()))
def readInt():
return int(input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))

a = []

def SieveOfEratosthenes(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
# If prime[p] is not changed, then it is a prime
if (prime[p] == True):
# Update all multiples of p
for i in range(p * 2, n+1, p):
prime[i] = False
p += 1
# Print all prime numbers
for p in range(2, n):
if prime[p]:
# print p,
a.append(p)


t=input()
SieveOfEratosthenes(1000001)
for __ in range(t):
l,r = map(int, raw_input().split())
count =0
for i in a:
if(i>=l and i<=r):
count+=1
ans = (float(count)/(r-l+1))
print("{0:.6f}".format(ans))
# print(count)
38 changes: 38 additions & 0 deletions CP/Hackon Feb/prob3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def readInts():
return list(map(int, raw_input().split()))
def readInt():
return int(input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))

t=input()
for __ in range(t):
a,b,c = readInts()
x,y,z = readInts()
root = pow(c+z,2)
line = pow(a-x,2) + pow(b-y,2)

if(root == line):
print("tangential")
elif(root>line):
print("overlapping")
else:
print("not overlapping")


'''
Input:
3
10 10 3
10 6 1
8 8 3
8 4 2
7 5 2
4 9 2
Output:
tangential
overlapping
not overlapping
'''
50 changes: 50 additions & 0 deletions CP/Hackon Feb/prob4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import math
def readInts():
return list(map(int, raw_input().split()))
def readInt():
return int(input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))


import math

def solve():
# T=int(input())
# for y in range(T):
k=int(input())
if k==1:
print(5)
else:
base=int(math.log(k+1,2))
diff=(k+1)-(2**base)
val=bin(diff)[2:] # to remove 0b
l=len(val)
# print(val,base,l)
ans = ""
if l!=base:
val='0'*(base-l)+val
# print("an improvement",val)
for i in val:
if i=='0':
ans += "5"
else:
ans += "8"
print(ans)
t = int(input())
for i in range(t):
solve()
'''
Input:
3
1
5
11
Output:
5
85
8555
'''
22 changes: 22 additions & 0 deletions CP/Hackon Feb/prob5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import math
def readInts():
return list(map(int, raw_input().split()))
def readInt():
return int(input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))

test = readInt()
for _ in range(test):
X1, Y1, R1 = readInts()
X2, Y2, R2 = readInts()
d = math.sqrt(((X2 - X1) ** 2) + ((Y2 - Y1) ** 2))
if d < abs(R1 - R2):
if R1 > R2:
print 'C1CC2'
else:
print 'C2CC1'
elif d == (R1 - R2):
print 'C2~C1'
else:
print 'NOT SATISFIED'
24 changes: 24 additions & 0 deletions CP/Hackon Feb/prob6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import math
def readInts():
return list(map(int, raw_input().split()))
def readInt():
return int(input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStr():
return raw_input()

t = int(raw_input())

while t>0:
t-=1
n = int(raw_input())
a = n*n+2*n+1
b = n*(n+1) # summation n
c = b*(2*n+1) # summation n2
d = b*b # summation n3
e = (2*n+2)
num = (a*b)/2+d/4-(e*c)/6
den = (a*n)+c/6-(e*b)/2
print(num,den)
print num/den
40 changes: 12 additions & 28 deletions CP/templates/temp.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
t=input()
for i in range(t):
n=input()
arr=map(int,raw_input().split())
s=sum(arr)
if s%4!=0:
print -1
else:
a,b,c=[0,0,0]
for i in arr:
if i%4==1:
a+=1
elif i%4==2:
b+=1
elif i%4==3:
c+=1
#print a,b,c
#a,b,c=[2,5,8]
ans=0
ans+=min(a,c)
ans+=b/2
oth=max(a,c)-min(a,c)
#print a,b,c
if b%2==0:
ans+=3*(oth/4)
else:
ans+=2+3*((oth-2)/4)
print ans
import math
def readInts():
return list(map(int, raw_input().split()))
def readInt():
return int(input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStr():
return raw_input()

for __ in range(readInt()):
n = readInt()

0 comments on commit 43e62d7

Please sign in to comment.