Skip to content

Commit

Permalink
Codemania
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypotter0 committed Feb 17, 2018
1 parent 42bcc80 commit 4174431
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CP/Codemania/prob2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
for nitish in range(int(raw_input())):
n=int(raw_input())
if(n==1):
print(1)
continue
mod=10**9+7

# x=((n*(n+1)*(2*n+1))//6)%mod
# y=((n*n+1-2*n)%mod)*(n//2)
# y=y%mod
# xx=n//2-1
# c=(((xx*(xx+1))%mod*(2-2*n))%mod+(xx*(xx+1)*(xx*2+1)*4)//6)%mod
print(((((n*(n+1))//2)%mod)*n)%mod)


# print((x+y+c)%(mod))
46 changes: 46 additions & 0 deletions CP/Codemania/prob3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import math
t = int(input())
for tc in range(t):
a = input()
b = input()
inta = 0
intb = 0
cnta = 0
cntb = 0
# 1st team
vala = a.find('!')
if vala > 0:
inta = int(a[:vala])
cnta = len(a) - vala
else:
inta = int(a)
valb = b.find('!')
# print(valb)
# 2nd team
if valb > 0:
intb = int(b[:valb])
cntb = len(b) - valb
else:
intb = int(b)
# print("cnta",cnta ,"cntb",cntb)
# fact(13) > 10^9 so calculate upto 12
while cnta > 0 and inta < 13:
# print("aaaaaa")
cnta -= 1
inta = math.factorial(inta)
while cntb > 0 and intb < 13:
# print("bbbbbb")
cntb -= 1
intb = math.factorial(intb)
# print("cnta",cnta ,"cntb",cntb)
if cnta == cntb:
if inta > intb:
print(1)
elif inta < intb:
print(-1)
else:
print(0)
elif cnta < cntb:
print(-1)
elif cnta > cntb:
print(1)
12 changes: 12 additions & 0 deletions CP/Codemania/prob4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import math
import sys
n=int(input())
mod = pow(10,9)+7
for i in range(n):
p , m = map(int , raw_input().split())
ans1 = pow(2*(p+1) , m , mod)%mod
ans2 = pow((p+1) , mod-2 , mod)%mod
ans3 = (p+1-m)%mod
ans = (ans1*ans2*ans3)%mod
# print(ans1,ans2,ans3)
print(ans)
Empty file added CP/Codemania/prob5.cpp
Empty file.
12 changes: 12 additions & 0 deletions CP/Educational Codeforces Round 38 (Rated for Div. 2)/prob1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
n=input()
s=raw_input()
vowels="aeiouy"
ans=""
i=0
while i<n:
ans+=str(s[i])
if s[i] not in vowels:
i+=1
continue
while i<n and s[i] in vowels:i+=1
print ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
n=input()
a=map(int,raw_input().split())
x=1
y=10**6
ans=min(a[n-1]-x,y-a[0])
for i in range(n-1):
ans=min(ans,max(a[i]-x,y-a[i+1]) )
print ans

43 changes: 43 additions & 0 deletions CP/Educational Codeforces Round 38 (Rated for Div. 2)/prob3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ps = [False]*(10**5)
ps[0] = True
ps[1] = True
for i in range(len(ps)):
if not ps[i]:
for k in range(i*i, i, len(ps)):
ps[k] = True
primes = [i for i, v in enumerate(ps) if not v]

t = int(raw_input())
for _ in range(t):
x = int(raw_input())
divs = set([1])
xol = x
if x == 0:
print("1 1")
continue
for p in primes:
if x <= 1: break
while x%p == 0:
d2 = set()
for d in divs:
d2.add(d*p)
divs |= d2
x //= p
ok = False
for d in divs:
d1, d2 = d, xol//d
if (d1+d2)%2 == 0:
n, nm = (d1+d2)//2, (max(d1,d2) - min(d1, d2))//2
if nm == 0: continue
m1 = n//nm
m2 = n//nm + 1
if m1 > 0 and n//m1 == nm:
print("{} {}".format(n, m1))
ok = True
break
if m2 > 0 and n//m2 == nm:
print("{} {}".format(n, m2))
ok = True
break
if not ok:
print(-1)
Empty file added CP/Encipher/prob2.py
Empty file.
Empty file.

0 comments on commit 4174431

Please sign in to comment.