Don't wanna be here? Send us removal request.
Text
Modulo 10^9+7 (1000000007)
https://www.geeksforgeeks.org/modulo-1097-1000000007/
0 notes
Text
python get two groups of values from set of array input
from itertools import product, combinations
def my_combos(A): subsets = [] for i in xrange(1, len(A)): subsets.append(list(combinations(A,i))) combos = [] for i in xrange(1, 1+len(subsets)/2): combos.extend(list(product(subsets[i-1], subsets[-i]))) if not len(A) % 2: combos.extend(list(combinations(subsets[len(A)/2-1], 2))) return [combo for combo in combos if not set(combo[0]) & set(combo[1])]
my_combos({1,2,3,4})
0 notes
Text
Python 3 code to find points where rectangles are intersecting. techgig . CODE4AVAILITY
''' Read input from STDIN. #print your output to STDOUT ''' #Use input() to read input from STDIN and use #print to write your output to STDOUT import sys def main():
No_of_times=7 #### int initialization No_of_times=int(input()) a=[0]*No_of_times
####initialize array matrix=[] for i in range (0,No_of_times): matrix.append([]) for j in range(0,5): matrix[i].append(0)
####Assign values to matrix for x in range(No_of_times): matrix[x]=list(input().strip().split(" "))
#####Create plotting area to be measured area=[] for i in range (0,1000): area.append([]) for j in range(0,1000): area[i].append(int(0)) #print(matrix) #print(matrix[0][0]) for q in matrix: x1=int(q[0]) x2=int(q[2]) y1=int(q[1]) y2=int(q[3]) for i in range(x1,x2+1): for j in range(y1,y2+1): area[i][j]=area[i][j]+1 ##print(i,j) #print ('\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in area]))
#price=[No_of_times][] count123=0 total=0 for q in matrix: x1=int(q[0]) x2=int(q[2]) y1=int(q[1]) y2=int(q[3]) count=0 for i in range(x1,x2+1): for j in range(y1,y2+1): if area[i][j]>1: count=count+1 #print (count,count123) total=total+int(count)*int(q[4]) count123=count123+1 #price[count123]=[q[4]][count]
##print (matrix) #print(str(total).strip()) outputint=0 outputint=total sys.stdout.write(str(outputint)) ####plotting the area
main()
0 notes
Text
Python 3 code to get GCD of set of arrays
input would come as below:
#Constraints
#1<= T <=5
#1<= N <=1⁰⁵
#1<= list_element <=1⁰⁶
3 3 4 5 6 4 45 56 78 89 6 2 4 5 6 78 9
''' Read input from STDIN. Print your output to STDOUT ''' #Python 3 - 3.7.1 #Use input() to read input from STDIN and use print to write your output to STDOUT from itertools import product, combinations import sys def computeGCD(x, y):
while(y): x, y = y, x % y
return x def multiplyList(myList) :
# Multiply elements one by one result = 1 for x in myList: result = result * int(x) return result
def my_combos(A): subsets = [] for i in range(1, len(A)): subsets.append(list(combinations(A,i)))
#print (subsets) combos = [] for i in range(1, int(1+len(subsets)/2)): combos.extend(list(product(subsets[i-1], subsets[-i])))
#print (combos) if not len(A) % 2: combos.extend(list(combinations(subsets[int(len(A)/2-1)], 2))) return [combo for combo in combos if not set(combo[0]) & set(combo[1])]
def main():
#Constraints #1<= T <=5 #1<= N <=10^5 #1<= list_element <=10^6
#List_of_elements=[] No_of_iterations=int(input())
for i in range(No_of_iterations):
No_of_elements=int(input()) List_of_elements=list(input().strip().split(" "))
#print(No_of_elements) #print(List_of_elements) test =my_combos(List_of_elements) count=0 #print (test) for i in test: fg=multiplyList(i[0]) gf=multiplyList(i[1])
#print(fg,gf) #print(computeGCD(fg,gf)) if computeGCD(fg,gf) == 1 : count=count+1 #print ('count',count) #sys.stdout.write(str(count)) #print ('count',count) print (count*2)
main()
1 note
·
View note