Article directory
- Eating candy
- recursive sequence
1. Eat candy IO link
Ideas for this question: The meaning of this question is the Fibonacci sequence!
#include <bits/stdc++.h>
typedef uint64_t i64;
i64 f(i64 n)
{
if(n==1) return 1;
if(n==2) return 2;
return f(n-1)+f(n-2);
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);std::cout.tie(nullptr);
i64 n;
std::cin>>n;
std::cout<<f(n)<<std::endl;
return 0;
}
2. Recursive sequence IO link
The idea of this question: Just follow the meaning of the question!
#include <bits/stdc++.h>
constexpr int N=10010;
typedef uint64_t i64;
i64 a[N];
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);std::cout.tie(nullptr);
i64 p,q,k;
std::cin>>a[0]>>a[1]>>p>>q>>k;
for(int i=2;i<=k;i++)
a[i]=(p*a[i-1]+q*a[i-2])%10000;
std::cout<<a[k]%10000<<std::endl;
return 0;
}