Mai intai trebuie sa te autentifici.
Cod sursa(job #1241069)
| Utilizator | Data | 12 octombrie 2014 16:26:45 | |
|---|---|---|---|
| Problema | Al k-lea termen Fibonacci | Scor | 5 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.75 kb |
#include <stdio.h>
#include <cstdlib>
using namespace std;
unsigned long x[2][2]={{0,1},{1,1}},n;
FILE *f1=fopen("kfib.in","r"),*f2=fopen("kfib.out","w");
void inmulteste(int putere)
{
unsigned long a[2][2]={{0,1},{1,1}},y,z,t;
for(;putere>0;putere--)
{
y=a[0][0]*x[0][1]+a[0][1]*x[1][1]%666013;
z=a[1][0]*x[0][0]+a[1][1]*x[1][0]%666013;
t=a[1][0]*x[0][1]+a[1][1]*x[1][1]%666013;
a[0][1]=y;
a[1][0]=z;
a[1][1]=t;
}
x[1][0]=a[1][0];
x[0][1]=a[0][1];
x[1][1]=a[1][1];
}
int main()
{
fscanf(f1,"%u",&n);
inmulteste(n-2);
fprintf(f2,"%u",x[1][1]);
return 0;
}
//Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.
