1000.InfiniteSequence
My Solution
Just memory search
// BEGIN CUT HERE
// END CUT HERE
#line 5 "InfiniteSequence.cpp"
#include <string>
#include <vector>
#include <map>
//#include <cmath>
using namespace std;
class InfiniteSequence {
public:
map<long long, long long> d;
long long calc(long long n, int p, int q) {
if(n == 0) return d[0] = 1;
d[n] = (d[n/p] != 0) ? d[n/p] : calc(n/p, p, q);
return d[n] += (d[n/q] != 0) ? d[n/q] : calc(n/q, p, q);
}
};
非特殊说明,本博所有文章均为博主原创,未经许可不得转载。
https://www.prolightsfxjh.com/
Thank you!
------from ProLightsfx
非特殊说明,本博所有文章均为博主原创,未经许可不得转载。
如经许可后转载,请注明出处:https://prolightsfxjh.com/article/1000-infinitesequence/
共有 0 条评论