forked from RK1905101/Mini_Python_Projects
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_template.py
More file actions
Latest commit
77 lines (63 loc) · 1.74 KB
/
Copy pathPython_template.py
File metadata and controls
77 lines (63 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Header files
fromsysimportstdin, stdout
frommathimportceil, gcd
# Input data
stdin=open("input", "r")
# Pre-defined values
mod=10**9+7
MAX=float('inf')
MIN=-float('inf')
# Pre-defined functions
# LCM of two numbers -> int
deflcm(a, b):
return (a*b) //gcd(a, b)
# Sum of all the digits of a number -> int
defsumdigit(n):
s=0
while(n):
s+=n%10
n//=10
returns
# Check if char is vowel or not -> bool
defisvowel(s):
ifsin ['a', 'e', 'i', 'o', 'u']:
returnTrue
returnFalse
# sum of all the numbers from 1 upto n -> int
deflinearsum(n):
ifn<=0:
return0
return (n* (n+1)) //2
# all Factors of a given number -> list
fromfunctoolsimportreduce
deffactors(n):
returnlist(set(reduce(list.__add__, ([i, n//i] foriinrange(1, int(n**0.5) +1) ifn%i==0))))
# No. of combinations (nCr) -> int
importfunctools
defncr(n, r):
r=min(r, n-r)
a=functools.reduce(lambdax, y: x*y, range(n, n-r, -1), 1)
b=functools.reduce(lambdax, y: x*y, range(1, r+1), 1)
returna//b
# returns base raised to power modulo mod -> int
deffast_power(base, power):
result=1
whilepower>0:
ifpower%2==1:
result= (result*base) %mod
power=power//2
base= (base*base) %mod
returnresult
# return inverse modulo of a number -> int
definverse_mod(q, mod):
returnfast_power(q, mod-2) %mod
# New function
deffunc():
# function body
return
# Actual Code begins here
for_inrange(int(stdin.readline())):
n=int(stdin.readline())
n, m=map(int, stdin.readline().split())
s=stdin.readline().strip()
arr=list(map(int, stdin.readline().split()))