This commit is contained in:
alexey_makov 2026-07-01 19:46:51 +03:00
commit 851751ea87
82 changed files with 2093 additions and 0 deletions

29
8B.py Normal file
View file

@ -0,0 +1,29 @@
import sys
from array import array
data = sys.stdin.read().split()
p = int(data[0])
if p == 2:
print(1)
sys.exit(0)
half = p // 2 + 1
inv = array('i', [0] * half)
inv[1] = 1
current_sum = 0
count = 0
for i in range(1, p):
if i == 1:
val = 1
elif i < half:
inv[i] = (p - (p // i) * inv[p % i]) % p
val = inv[i]
else:
val = (p - (p // i) * inv[p % i]) % p
current_sum = (current_sum + val) % p
count += 1
if count == 100:
print(current_sum)
current_sum = 0
count = 0
if count > 0:
print(current_sum)