用AI更多的是让他帮我调代码,,

#Prompt分享#
Prompt名称:帮我修改c++代码并解释
适用工具:豆包
提示词正文:
int fib(int x)
{
    if(x==1||x==2) return 1;
    int res[N][N]={{1},{0}}; // E*{{f(2)},{f(1)}} 初始值
    int a[N][N]={{1,1},{1,0}};   // 固定转移矩阵
    int power=x-1;  
    while(power)
    {
        if(power&1) mul(res,a);  // res = res * a
        mul(a,a);                // a = a * a
        power>>=1;
    }
    return res[0][0] % mod;
}为什么把res改成这样也是对的?这三种res你放一起对比一下

效果展示:
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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