题解 | #雾粉与数论# 我和Mathematica,ChatGPT合力砍下牛客练习赛126的B题

雾粉与数论

https://ac.nowcoder.com/acm/contest/84527/B

我和Mathematica,ChatGPT合力砍下牛客练习赛126的B题。我们仨个真厉害。

题目描述

结果对1e9+7取模。

代码

# Clear[n]
# f[n_] := Sum[GCD[i*(i - 1)/2, i*(i + 1)/2], {i, 2, n}]
# f /@ Range[1, 30, 1]
# FindSequenceFunction[%5713, n]


# ```
# \frac{1}{16} (-1)^n \left(6 (-1)^n n^2+6 (-1)^n n-2 n-15 (-1)^n-1\right)
# ```

# rewrite it in python code.


# refine my code.


n = int(input())
mod = 1000000007

# Calculate components of the expression
sign = (-1) ** n
n_squared = n ** 2

# Define the expression with precomputed components
# The (1/16) factor will be handled by multiplying by the modular inverse of 16 mod 1000000007
expression = sign * (6 * sign * n_squared + 6 * sign * n - 2 * n - 15 * sign - 1)

# Modular inverse of 16 mod 1000000007
mod_inverse_16 = pow(16, mod - 2, mod)

# Compute the result with integer arithmetic and apply the modular inverse
result = (expression * mod_inverse_16) % mod

print(result)
全部评论
没必要写这么长,观察题
点赞 回复 分享
发布于 03-20 09:21 北京

相关推荐

05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
代码飞升:别用口语,后端就写后端,前端就写前端,最后别光后悔
点赞 评论 收藏
分享
07-10 11:08
门头沟学院 Java
投递京东等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务