QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#671178#9225. Fibonacci FusionLegend_dyTL 845ms21068kbPython31.5kb2024-10-24 11:29:392024-10-24 11:29:41

Judging History

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

  • [2024-10-24 11:29:41]
  • 评测
  • 测评结果:TL
  • 用时:845ms
  • 内存:21068kb
  • [2024-10-24 11:29:39]
  • 提交

answer

import math
import sys
sys.set_int_max_str_digits(0)

sq5 = math.sqrt(5)

P = 1000000000000000009
fio = [0, 1]
for i in range(50):
    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):
            for k in range(0, 2):
                m3[i][j] = (m3[i][j] + m1[i][k] * m2[k][j] % P) % P
    return m3

def Fio(n):
    if n <= 20:
        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[1][0]

def get(x):
    if x <= 20:
        y = 1
        while True:
            if Fio(y) >= x:
                return y
            y += 1
    return math.ceil((math.log2(sq5) + math.log2(x)) / math.log2((1 + sq5) / 2))

n = int(input())
a = []
for i in range(0, n):
    a.append(int(input()))
# a.append(Fio(21) - 11)
# a.append(Fio(20) - 23)
# a.append(Fio(20) - 31)
# a.append(11)
# a.append(23)
# a.append(31)

a = sorted(a)

ans = 0

mp = {-1:0}

# k = get(10 ** 2000000)
# print(k)
# print(Fio(19))
# print(Fio(20))
# print(Fio(21))
for j in range(0, n):

    i = get(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)
    ans += mp.get((Fio(i + 3) - a[j] + P) % P, 0)

    if mp.get(a[j], 0) == 0:
        mp.update({a[j]:1})
    else:
        mp[a[j]] += 1


print(ans)

詳細信息

Test #1:

score: 100
Accepted
time: 14ms
memory: 10704kb

input:

6
50
8
8
5
72
354224848179261915070

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 845ms
memory: 21068kb

input:

28
200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...

output:

27

result:

ok 1 number(s): "27"

Test #3:

score: 0
Accepted
time: 772ms
memory: 13400kb

input:

5187
2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...

output:

6073

result:

ok 1 number(s): "6073"

Test #4:

score: 0
Accepted
time: 404ms
memory: 14276kb

input:

200000
2
2
2
2
1
2
1
1
2
2
1
1
1
2
2
1
1
2
1
1
2
2
1
2
2
2
1
1
1
1
2
2
1
2
1
2
1
1
2
2
1
1
1
2
1
1
2
1
2
2
2
2
1
2
2
1
1
1
2
1
1
1
1
1
2
1
2
2
1
1
1
2
2
2
1
1
2
1
1
2
1
2
1
1
1
2
2
2
1
1
1
1
2
1
2
1
1
2
2
1
1
2
1
1
2
1
2
2
1
2
1
2
2
1
1
2
1
1
1
2
2
2
1
2
2
1
1
2
2
2
2
1
2
1
1
2
1
2
2
1
1
1
1
2
2
2
2...

output:

15003749259

result:

ok 1 number(s): "15003749259"

Test #5:

score: -100
Time Limit Exceeded

input:

200000
944176313232170622314
2590599414036674999101
753315073608896000424
9299685298577430049245
9361800333778142620806
8988699166328904060999
9606920674025578304023
4203331868598952026136
5183047027116137697788
3968714342776915029801
8130984095583566992354
3206443643596048048798
6248561214283254355...

output:


result: