Skip to content

Instantly share code, notes, and snippets.

@MiSawa
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiSawa/85acd3277a94c8bad869 to your computer and use it in GitHub Desktop.
Save MiSawa/85acd3277a94c8bad869 to your computer and use it in GitHub Desktop.
// 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