QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#669440#9225. Fibonacci FusionLegend_dy#RE 13ms10776kbPython31.3kb2024-10-23 18:37:062024-10-23 18:37:08

Judging History

你现在查看的是最新测评结果

  • [2024-10-23 18:37:08]
  • 评测
  • 测评结果:RE
  • 用时:13ms
  • 内存:10776kb
  • [2024-10-23 18:37:06]
  • 提交

answer

import math

sq5 = math.sqrt(5)

P = 1000000000000002097
fio = [0, 1]
for i in range(1000):
    fio.append((fio[-1] + fio[-2]) % P)

def mul(m1, m2):
    m3 = [[0, 0], [0, 0]]
    for i in range(0, 2):
        for j in range(0, 2):
                m3[i][j] = (m1[i][0] * m2[0][j] % P + m1[i][1] * m2[1][j] % P) % P
    return m3

def Fio(n):
    if n <= 0:
        while True: 
            n = 1
      
    if n <= 500:
        return fio[n]
    y = [[1, 0], [0, 1]]
    x = [[0, 1], [1, 1]]
    while n > 0:
        if n % 2 == 1:
            y = mul(y, x)
        x = mul(x, x)
        n //= 2
    return y[0][0]

def gett(x):
    if x <= 100:
        y = 0
        while True:
            if fio[y] >= x:
                return y
            y += 1
            
    return math.ceil(math.log2(sq5 * x) / math.log2((1 + sq5) / 2))

n = int(input())
a = []
for i in range(0, n):
    a.append(int(input()))

a = sorted(a)

ans = 0
mp = {-1:0}

for j in range(0, n):
    i = gett(a[j])

    a[j] %= P
    ans += mp.get((Fio(i) - a[j] + P) % P, 0)
    ans += mp.get((Fio(i + 1) - a[j] + P) % P, 0)    
    ans += mp.get((Fio(i + 2) - a[j] + P) % P, 0)
    if mp.get(a[j], 0) == 0:
        mp.update({a[j]:1})
    else:
        mp[a[j]] += 1


print(ans)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 10776kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: -100
Dangerous Syscalls

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:


result: