Skip to content

Instantly share code, notes, and snippets.

@mcleary
Created May 26, 2016 13:04
Show Gist options
  • Save mcleary/bfc75e92e8b82ac95380aeee8e379738 to your computer and use it in GitHub Desktop.
Save mcleary/bfc75e92e8b82ac95380aeee8e379738 to your computer and use it in GitHub Desktop.
Fibonacci Factor
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int numbers_count;
cin >> numbers_count;
vector<int> numbers;
for(int i = 0; i < numbers_count; ++i)
{
int number;
cin >> number;
numbers.push_back(number);
}
for(int number : numbers)
{
bool found = false;
unsigned long int fib0 = 1, fib1 = 1;
while (!found)
{
unsigned long long fib_n = fib1 + fib0;
fib0 = fib1;
fib1 = fib_n;
for (unsigned long long int k = 2; k <= number; ++k)
{
if (number % k == 0 && fib_n % k == 0)
{
cout << fib_n << " " << k << endl;
found = true;
break;
}
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment