1414.cpp (559B)
1 class Solution { 2 typedef array<int, 45> cache_t; 3 static inline constexpr const cache_t cache = []() constexpr -> cache_t { 4 cache_t cache; 5 cache[0] = cache[1] = 1; 6 for (int i = 2; i < cache.size(); i++) 7 cache[i] = cache[i - 1] + cache[i - 2]; 8 return cache; 9 }(); 10 11 public: 12 int findMinFibonacciNumbers(int k) { 13 int res = 0; 14 for (auto it = upper_bound(begin(cache), end(cache), k); k > 0; it--) 15 while (k >= *it) 16 k -= *it, res++; 17 return res; 18 } 19 };