Last active
August 29, 2015 14:16
-
-
Save MiSawa/85acd3277a94c8bad869 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://codeiq.jp/ace/kawazoe/q1339 | |
#include <iostream> | |
#include <vector> | |
long long k_bonacci(const int &k, const int &n){ | |
std::vector<long long> v(k, 0); | |
long long res = v.back() = 1; | |
for(int i = 0; i < n; ++i) std::swap(v[i%k] = res * 2 - v[i%k], res); | |
return res; | |
} | |
int main(){ | |
int n, k; | |
std::cin >> n >> k; | |
std::cout << k_bonacci(k+1, n) - k_bonacci(k, n) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment