2个tle,why?

P2626 斐波那契数列(升级版)

复杂度 $\operatorname{fib}(k)$ 有啥道理不 T 来着。
by N_z_ @ 2024-04-05 10:51:57


@[HuangZihan181](/user/1073167) 你没有取模吧
by Rieman_sum @ 2024-04-05 11:01:03


@[Guo1](/user/743879) 取模了还是不行 ```cpp //https://www.luogu.com.cn/problem/P2626 #include<bits/stdc++.h> using namespace std; const long long MOD=pow(2,31); int f(int n){ if(n==1||n==2){ return 1; } return (f(n-1)+f(n-2))%MOD; } int main() { int n,x; cin>>n; int k=f(n); cout<<k<<"="; for(int i=2;i<=k;i++){ while(k%i==0){ x++; if(x==1){ cout<<i; } else{ cout<<"*"<<i; } k/=i; } } return 0; } ```
by HuangZihan181 @ 2024-04-05 11:19:58


|