long long fibonacci_fast(long long n) {
long long a[n]{0};
a[0]=0;
a[1]=1;
for(int i=2;i<=n;i++)
a[i]=a[i-1]+a[i-2];
return a[n];
}
and the fuction to calculate pisano period is
long long get_pisano_period(long long n,long long m){
vector<long long> vec{0,1};
for(int i=2;i<=n;i++){
vec.push_back(fibonacci_fast(i)%m);
long c{2};
for(int i=2;i<=n;i++){
if((vec[i]!=0) && (vec[i+1]!=1)){
c++;
}}
return c;
}
In main function i m just outputing the output of get_pisano_period(n,m)
Aucun commentaire:
Enregistrer un commentaire