Pagini recente » Cod sursa (job #1588838) | Cod sursa (job #957638) | Cod sursa (job #702031) | Cod sursa (job #2806142) | Cod sursa (job #924043)
Cod sursa(job #924043)
#include <fstream>
#define R9 666013
#define NM 10
using namespace std;
long long i, j, k, n, m, a[NM][NM], b[NM][NM], c[NM][NM];
ifstream fin("kfib.in");
ofstream fout("kfib.out");
void inmultire(long long a[NM][NM], long long b[NM][NM], long long c[NM][NM]) {
long long i, j, k;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
c[i][j] = 0;
for (k = 0; k < n; k++)
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % R9;
}
}
void atribuire(long long a[NM][NM], long long b[NM][NM]) {
long long i, j;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
a[i][j] = b[i][j];
}
int main() {
n = 2;
fin >> m;
fin.close();
m -= 2;
c[0][0] = c[1][1] = 1;
c[1][0] = c[0][1] = 0;
a[0][0] = 0;
a[0][1] = a[1][0] = a[1][1] = 1;
while (m) {
if (m % 2) {
inmultire(a, c, b);
atribuire(c, b);
}
inmultire(a, a, b);
atribuire(a, b);
m /= 2;
}
fout << (c[1][0] + c[1][1]) % R9;
return 0;
}