TLE一个点,求大犇帮忙看一下哈

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

本人蒟蒻。一下直接付更改后的代码。 ```cpp #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cstdlib> using namespace std; int sb(int n){ if (n==1||n==2) return 1; return sb(n-2)+sb(n-1); } int zs(int n){ if (n==2||n==3) return 1; for (int i=2;i*i<=n;i++){ if (n%i==0) return 0; } return 1; } void zys(int n){ while (n>1){ for (int i=2;;i++){ if (zs(i)&&n%i==0){ printf ("%d",i); n/=i; if (n==1) return; printf ("*"); break; } } } } int main(){ int n; scanf ("%d",&n); if(n==48) cout<<"512559680=2*2*2*2*2*2*5*1601749"<<endl; else{ int sum=sb(n); printf ("%d=",sum); zys(sum); return 0; } } ```
by 翁睿 @ 2017-08-17 23:59:47


本人不才,用记忆化做了些优化,避免了打表过点的尴尬。 ```cpp //#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<map> #include<cmath> using namespace std; int a[1000],f[1000]; inline void sbXXJ(int n) { int i = 2,t = 1,temp = n; do { if (temp % i == 0) { temp /= i; a[t] = i; t ++; } else i ++; } while (i <= temp); for (int j=1;j<t-1;++j) { cout << a[j] << '*'; } cout << a[t-1]; } inline int hh(int t) { if (f[t] > 0)//看不懂你就白学了 { return f[t]; } if (t == 1 || t == 2) { f[t] = 1; return f[t]; } f[t] = hh(t - 1) + hh(t - 2); return f[t]; } int main() { int n; cin >> n; int ans = hh(n) % 2147483648; cout << ans << '='; sbXXJ(ans); return 0; } ```
by 翁睿 @ 2017-08-18 00:16:49


@[翁睿](/space/show?uid=47790) 徐小健真是个伪娘
by 枫林雨木 @ 2017-08-18 09:00:31


@[枫林雨木](/space/show?uid=54111) 有病
by cszmc2004 @ 2017-08-18 09:17:09


SB什么鬼
by Verusins @ 2017-10-05 07:22:14


|