Cod sursa(job #2857786)

Utilizator Max_CalincuMaxim Calincu Max_Calincu Data 26 februarie 2022 12:33:16
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.17 kb
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair<ll, ll>
#define sz(x) (int)((x).size())
#define all(a) (a).begin(), (a).end()

/* int f[maxn],nf[maxn],inv[maxn];
const int M=998244353;
void init(){
    inv[1]=1; for (int i=2;i<maxn;i++) inv[i]=M-1ll*(M/i)*inv[M%i]%M;
    f[0]=nf[0]=1; for (int i=1;i<maxn;i++) f[i]=1ll*f[i-1]*i%M,nf[i]=1ll*nf[i-1]*inv[i]%M;
}
int C(int x,int y){return 1ll*f[x]*nf[y]%M*nf[x-y]%M;}*/
const ll mod = 666013;
ll n, k, m, mi, ma;

double lpow(double x, ll p){
	if(p == 0) return 1.0;
	double f = lpow(x, p/2);
	f = f*f;
	if(p%2) f = f*x;
	while(f > mod) f -= mod;
	return f;
}

void solve(){
	
	ifstream cin("kfib.in");
	ofstream cout("kfib.out");
	
	cin >> n;
	double f1 = (1 + sqrt(5))*1.0/2, f2 = (1 - sqrt(5))*1.0/2; 
	double ans = lpow(f1, n) - lpow(f2, n);
	ans *= sqrt(5)/5;
	while(ans < 0) ans += mod;
	while(ans > mod) ans -= mod;
	ll f = (ll) ans;
	cout << f << "\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t=1;
	//cin >> t;
	while(t--) solve();
	
	return 0;
}