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
42bcc80
commit 4174431
Showing
9 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
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,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)) |
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,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) |
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 @@ | ||
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.
12 changes: 12 additions & 0 deletions
12
CP/Educational Codeforces Round 38 (Rated for Div. 2)/prob1.py
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 @@ | ||
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 |
9 changes: 9 additions & 0 deletions
9
CP/Educational Codeforces Round 38 (Rated for Div. 2)/prob2.py
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,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
43
CP/Educational Codeforces Round 38 (Rated for Div. 2)/prob3.py
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,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.
Empty file.