跳到正文

题解

题解:P9929 [NFLSPC #6] 挑战大数因子分解

lrz2024012101约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年3月25日
更新
2026年5月22日
篇幅
约 1 分钟
题目
P9929

版本

  1. v2当前
  2. v1

高精度用Python

Python
import sys
sys.setrecursionlimit(int(1e7))
sys.set_int_max_str_digits(int(1e7))

def exgcd(a, b):
	if b == 0:
		return (1, 0, a)
	(x1, y1, v) = exgcd(b, a % b)
	return (y1, x1 - (a // b) * y1, v)

(s3, s5, s7, s1) = map(int, input().strip().split(' '))
C = int(input())

s4p = s3 - s5
s6 = 2 * s5 - s3

(k, M, v) = exgcd(s4p, s6)

C //= v
s4p //= v
s6 //= v

ans = (M % s4p + s4p) % s4p * C

if (ans <= s1):
	ans += (s1 - ans + s4p) // s4p * s4p
if (ans >= s7):
	ans -= (ans - s7 + s4p) // s4p * s4p

print(ans)
原文