29 lines
545 B
Python
Executable file
29 lines
545 B
Python
Executable file
import random
|
|
|
|
def calc(A):
|
|
n = len(A)
|
|
res = 0
|
|
for i in range(0,n):
|
|
for j in range(i+1, n):
|
|
res += A[j] - A[i]
|
|
return res
|
|
|
|
def calc2(A):
|
|
n = len(A)
|
|
res = 0
|
|
for i in range(0,n):
|
|
res += (2*(i+1)-n-1)*A[i]
|
|
return res
|
|
|
|
def main():
|
|
for i in range(0,100):
|
|
A = []
|
|
for j in range(0,i):
|
|
A.append(random.randint(0,1000000))
|
|
if not calc(A) == calc2(A):
|
|
print("wrong!")
|
|
return
|
|
print("ok!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|