#第三,五点过不去 求大神指点 和数据

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

我的三个点超时……第五个点对了
by 飞奔的蜗牛 @ 2017-06-08 20:03:24


你没必要搞一个数组啊,太占空间了,就弄三个变量,“轮换就行了”
by 飞奔的蜗牛 @ 2017-06-08 20:04:38


```cpp #include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> using namespace std; long long k=2147483648,a,b,c; int i,n; int zs (int x) { if (x==2) return 1; for (int i=2;i*i<=x;i++) if (x%i==0) return 0; return 1; } int main() { cin>>n; if (n==1) { cout<<"1"; return 0; } a=b=1; for (i=3;i<=n;i++) { c=a+b; c%=k; a=b; b=c; } k=2; cout<<c<<"="; while (1) { if (c%k==0 && c/k!=1) { cout<<k<<"*"; c/=k; } if (c%k==0 && c/k==1) { cout<<k; return 0; } if (c%k!=0) break; } k=3; while (1) { if (!zs(k)) {k+=2; continue;} if (c%k==0 && c/k!=1) { cout<<k<<"*"; c/=k; } if (c%k==0 && c/k==1) { cout<<k; return 0; } if (c%k!=0) k+=2; } return 0; } ```
by 飞奔的蜗牛 @ 2017-06-08 20:05:40


|