QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#316881 | #8177. Sum is Integer | ucup-team2000# | RE | 0ms | 0kb | Python3 | 1.1kb | 2024-01-28 05:28:39 | 2024-01-28 05:28:40 |
answer
import io,os,sys
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
input = sys.stdin.readline
p1 = 23513892331597
p2 = 999998727899999
p3 = 19489355557003
pn = []
qn = []
n = int(input())
for i in range(n):
x, y = list(map(int, input().split()))
pn.append(x)
qn.append(y)
def get_array(p):
arr = [(pn[i] * pow(qn[i], p-2,p)) % p for i in range(n)]
for i in range(1,n):
arr[i] = (arr[i] + arr[i-1]) % p
return arr
A = get_array(p1)
B = get_array(p2)
C = get_array(p3)
all = [A,B,C]
k = 2
res = []
for i in range(n):
vals = []
for ii in range(k):
for jj in range(ii+1,k):
vals.append(all[ii][i] - all[jj][i])
# print(vals)
res.append(vals)
res.append([0 for i in range(k) for j in range(i+1,k)])
res = list(sorted(res))
# print(res)
ans = 0
for i in range(n+1):
if i > 0 and res[i] == res[i-1]:
continue
j = i
while j + 1 < n+1 and res[j+1] == res[i]:
j += 1
# print(f"i: {i}, j: {j}")
len = j - i + 1
ans += (len) * (len - 1) // 2
print(ans)
详细
Test #1:
score: 0
Dangerous Syscalls
input:
4 1 6 1 3 1 2 1 2