Pagini recente » Cod sursa (job #2109328) | Cod sursa (job #43943) | Cod sursa (job #2367517) | Cod sursa (job #2294440) | Cod sursa (job #1246113)
#include <stdio.h>
#define mod 666013
unsigned int KthTerm(int k)
{
unsigned int firstTerm = 1, secondTerm = 1, saver;
// We already know the first 2 numbers, that's why we subtract 2.
for(int i = 0; i < k - 2; i++) {
saver = secondTerm;
secondTerm = (firstTerm + secondTerm) % mod;
firstTerm = saver;
}
return secondTerm;
}
int main()
{
int k;
FILE *inputFile = fopen("kfib.in", "r");
FILE *outputFile = fopen("kfib.out", "w");
// Read the number from the input file and store it in a variable.
fscanf(inputFile, "%d", &k);
// Print the kth number to the output file.
fprintf(outputFile, "%u", KthTerm(k));
// Close the files.
fclose(inputFile);
fclose(outputFile);
return 0;
}