forked from harrypotter0/algorithms-in-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb9f0dd
commit 43e62d7
Showing
8 changed files
with
195 additions
and
28 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |