Pagini recente » Cod sursa (job #1649429) | Cod sursa (job #678001) | Cod sursa (job #2117467) | Cod sursa (job #3313387) | Cod sursa (job #3326648)
#include <fstream>
using namespace std;
const int N = 2;
const int MOD = 666013;
void produs(int a[N][N], int b[N][N])
{
int aux[N][N] = {{0, 0}, {0, 0}};
for (int i = 0; i < N; i++)
{
for (int k = 0; k < N; k++)
{
for (int j = 0; j < N; j++)
{
aux[i][k] = (aux[i][k] + (long long)a[i][j] * b[j][k] % MOD) % MOD;
}
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
a[i][j] = aux[i][j];
}
}
}
int main()
{
ifstream in("kfib.in");
ofstream out("kfib.out");
int n;
in >> n;
n--;
int p[N][N] = {{1, 0}, {0, 1}};
int a[N][N] = {{1, 1}, {1, 0}};
while (n != 0)
{
int cif = n % 2;
if (cif != 0)
{
produs(p, a);
}
produs(a, a);
n /= 2;
}
out << p[0][0] << "\n";
in.close();
out.close();
return 0;
}