惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
博客园_首页
S
SegmentFault 最新的问题
罗磊的独立博客
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
D
Docker
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
V
V2EX
大猫的无限游戏
大猫的无限游戏
V
Visual Studio Blog
腾讯CDC
宝玉的分享
宝玉的分享
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
Vercel News
Vercel News
H
Help Net Security
博客园 - Franky
D
DataBreaches.Net
aimingoo的专栏
aimingoo的专栏

hsfzxjy 的博客

解决 VSCode + CMake + MSVC 编译器信息乱码的问题 使用 3090 部署 1.58bit 动态量化版 DeepSeek R1 671b 如何在 VS Code DevContainer 中配置 HTTP 代理 如何在跳板机背后的服务器上使用 VS Code Remote - Containers Cohesive Digests for Ints and Floats Rust 中的隐匿概念 —— Place(位置) 美术馆 一尺之槌,日取其半,1075日而竭 老生常谈:使用 Cloudflare 自选 IP 加速站点访问 辩义 State、Nation 与 Country 将 Base64 编码的数据快速转换为 Uint8Array 折腾 NPU·第1章 —— 搭建 Level Zero 开发环境 折腾 NPU·第0章 —— Intel NPU 概述与 Level-Zero 新增域名 monad.run CSS 中为特定字符设置不同字体 Arbitary Lifetime Transmutation via Rust Unsoundness Dijkstra 算法的延伸 Manacher 回文计数算法 硬卧 Go Fact: Zero-sized Field at the Rear of a Struct Has Non-zero Size Display *big.Rat Losslessly and Smartly in Golang 代码的仪式 Building Electron From Scratch 中式亲属称谓研究之一:构建半群 Some Notes on Kotlin Coroutines Git sparse-checkout and partial clones for Mega-Repos 辩义“封建” Diving from the CUDA Error 804 into a bug of libnvidia-container Modern Cryptography, GPG and Integration with Git(hub) Move the Root Partition of Ubuntu
UVa11582 Colossal Fibonacci Numbers! && 大数操作
2014-10-01 · via hsfzxjy 的博客

链接:Link 耗时:0.139s

前言

这道题的主要思路就是打表,看看 Fibonacci 数列模 n 几个一循环。但由于这题给的数太大了,从而在细节上耗了很久。在此记录一下:

var
x: qword;
y: longint;
begin
x := 1<<64-1;
y := 100;
x := x mod y;
x := x mod qword(y);
end.

Code

var
a,b: qword;
_, n, i, k, cnt: longint;
f: array [1..1000000] of longint;

function superMod(a, b: qword; m: longint): longint;
var
x: qword;
begin
if b = 0 then
exit(1);
x := superMod(a, b shr 1, m);
superMod := x * x mod m;
if odd(b) then
superMod := superMod * a mod m;
end;

begin
assign(input, 'main.in'); reset(input);
assign(output, 'main.out'); rewrite(output);
readln(_);
while _ > 0 do
begin
dec(_);
readln(a, b, n);
if a = 0 then
begin
writeln(0);
continue;
end;
if n = 1 then
begin
writeln(0);
continue;
end;
f[1] := 1;
f[2] := 1;
cnt := 2;
while not ((f[cnt-1] = 1) and (f[cnt] = 0)) do
begin
inc(cnt);
f[cnt] := (f[cnt-1] + f[cnt-2]) mod n;
end;


a := a mod qword(cnt);
k := superMod(a, b, cnt);
writeln(f[k]);
end;
close(output); close(input);
end.

作者:hsfzxjy
链接:
许可:CC BY-NC-ND 4.0.
著作权归作者所有。本文不允许被用作商业用途,非商业转载请注明出处。