Pagini recente » Arhiva de probleme | Cod sursa (job #1704465) | Cod sursa (job #1454368) | Istoria paginii utilizator/frigura-iliasa.flavia-mihaela | Cod sursa (job #2280467)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("kfib.in");
ofstream fout("kfib.out");
int n;
int a[2][2],b[2][2];
void inmultire_matrici(int f1[2][2], int f2[2][2])
{
int f[2][2];
f[0][0] = f1[0][0] * f2[0][0] + f1[0][1] * f2[1][0];
f[0][1] = f1[0][0] * f2[0][0] + f1[0][1] * f2[1][1];
f[1][0] = f1[1][0] * f2[0][0] + f1[1][1] * f2[1][0];
f[1][1] = f1[1][0] * f2[0][1] + f1[1][1] * f2[1][1];
for(int i=0;i<=1;i++)
for(int j=0;j<=1;j++)
{
f2[i][j] = f[i][j];
}
}
int main()
{
fin>>n;
if(n==0)
fout<<0;
else
{
a[0][0]=0;
a[0][1]=1;
a[1][0]=1;
a[1][1]=1;
b[0][0]=0;
b[0][1]=1;
b[1][0]=1;
b[1][1]=1;
for(int k=1;k<=n-2;k++)
inmultire_matrici(a,b);
fout<<b[1][1]%666013;
}
return 0;
}